Click or drag to resize

StrixRpcAttributeProcedureCode Property

Code used to identify the method.

Namespace:  SoftGear.Strix.Unity.Runtime
Assembly:  StrixUnityRuntime (in StrixUnityRuntime.dll) Version: 1.5.0
Syntax
C#
public int ProcedureCode { get; set; }

Property Value

Type: Int32
Remarks
Smaller values decrease the network packet size. Although, you have to be careful to keep the values unique across all the RPC methods on the current type. If set to 0, method name hash is used instead. The default value is 0.
Examples
In this example we use RPC to update character's health instead of a StrixSyncField in order to add a visual effect when the hit was strong enough. We also use StrixRpcContext to get information about the client who sent the RPC. OnMouseDown method is called by Unity when you click this object (the object also needs a collider). When this happens we invoke an RPC using RpcToAll method and pass the name of the method ("Hit") along with the integer damage argument. Note that the actual Hit method has two arguments instead of one. The StrixRpcContext argument is a special optional argument the data for which is supplied by Strix. Also note that we used 1 as a ProcedureCode in StrixRpc attribute. This is done to minimize the RPC network packet size since smaller values are better compressed. Although we have to make sure that we use each code only once. All the clients that receive the RPC check the damage amount independently and spawn a blood visual effect if the damage was greater than or equal to 5. This way the blood effect is fully local for each client and doesn't have to be replicated, and as a result the network traffic will also be reduced.
using SoftGear.Strix.Unity.Runtime;
using UnityEngine;

public class RpcExample : StrixBehaviour
{
    public GameObject BloodPrefab;
    public int Health = 100;

    private void OnMouseDown()
    {
        RpcToAll("Hit", Random.Range(3, 8));
    }

    [StrixRpc(ProcedureCode = 1)]
    public void Hit(int damage, StrixRpcContext strixRpcContext)
    {
        Health = Mathf.Max(0, Health - damage);

        if (damage >= 5)
            Instantiate(BloodPrefab, transform.position, Quaternion.identity);

        Debug.Log(name + " received " + damage + " damage from " + strixRpcContext.sender.GetName());        
    }
}
See Also