示例#1
0
    /// <summary>
    /// Raises the packet event.
    /// </summary>
    /// <param name="packet">Packet.</param>
    public void OnPacket(RTPacket packet)
    {
        switch ((SparkManager.OpCode)Enum.ToObject(typeof(SparkManager.OpCode), packet.OpCode))
        {
        case SparkManager.OpCode.Sync:

            SparkStream      stream = SparkExtensions.Deserialize <SparkStream>(packet.Data.GetString(1));
            SparkMessageInfo info   = SparkExtensions.Deserialize <SparkMessageInfo>(packet.Data.GetString(2));

            foreach (SparkBehaviour behaviour in ObservedBehaviours)
            {
                if (stream.NetGuid == behaviour.netGuid)
                {
                    SendEvent_OnSerializeSparkView(behaviour, stream, info);
                }
            }

            break;

        case SparkManager.OpCode.SparkView_RPC:

            // RPC handling

            SparkRPC rpc = SparkExtensions.Deserialize <SparkRPC>(packet.Data.GetString(1));

            foreach (SparkBehaviour behaviour in ObservedBehaviours)
            {
                if (behaviour.netGuid == rpc.NetGuid)
                {
                    behaviour.Call(rpc.MethodName, rpc.Parameters);
                }
            }

            break;

        case SparkManager.OpCode.SparkView_LocalRPC:
            SparkRPC localRpc = SparkExtensions.Deserialize <SparkRPC>(packet.Data.GetString(1));

            if (localRpc.NetGuid == netGuid)
            {
                this.Call(localRpc.MethodName, localRpc.Parameters);
            }

            break;
        }
    }
示例#2
0
    /// <summary>
    /// Raises the packet event.
    /// </summary>
    /// <param name="packet">Packet.</param>
    private void OnPacket(RTPacket packet)
    {
        switch ((OpCode)Enum.ToObject(typeof(OpCode), packet.OpCode))
        {
        case OpCode.Sync:

            // Synchronization handling

            foreach (SparkView view in sparkViews)
            {
                view.OnPacket(packet);
            }

            break;

        case OpCode.RPC:

            // RPC handling

            SparkRPC rpc = SparkExtensions.Deserialize <SparkRPC>(packet.Data.GetString(1));

            foreach (SparkView view in sparkViews)
            {
                if (rpc.ReceiverIds.Contains(view.sparkPeer.id))
                {
                    foreach (SparkBehaviour behaviour in view.ObservedBehaviours)
                    {
                        behaviour.Call(rpc.MethodName, rpc.Parameters);
                    }
                }
            }

            break;

        case OpCode.LocalRPC:

            SparkRPC localRpc = SparkExtensions.Deserialize <SparkRPC>(packet.Data.GetString(1));

            this.Call(localRpc.MethodName, localRpc.Parameters);

            break;

        case OpCode.SparkView_RPC:

            // RPC handling

            foreach (SparkView view in sparkViews)
            {
                view.OnPacket(packet);
            }

            break;

        case OpCode.SparkView_LocalRPC:

            foreach (SparkView view in sparkViews)
            {
                view.OnPacket(packet);
            }

            break;
        }
    }