Esempio n. 1
0
        public override void Deserialize(NetworkReader reader)
        {
            this.bits = 0;

            {
                action = reader.ReadByte();

                if (action == 0)
                {
                    throw new Exception("action is 0");
                }

                NetworkInstanceId instanceId;
                instanceId = reader.ReadNetworkInstanceId();
                netObj     = null;

                netObj = conn.GetObject(instanceId);
                if (netObj == null)
                {
                    return;
                }

                switch (action)
                {
                case Action_ResponseSyncVar:
                    while (true)
                    {
                        byte b = reader.ReadByte();
                        if (b == 0)
                        {
                            break;
                        }
                        uint bits = (uint)(1 << (b - 1));
                        this.bits |= bits;
                        var    state = netObj.GetStateByBits(bits);
                        object value = null;

                        value = Read(reader, state.syncVarInfo.field.FieldType);

                        try
                        {
                            state.value = value;
                            if (netObj != null)
                            {
                                if (state.syncVarInfo.changeCallback != null)
                                {
                                    state.syncVarInfo.changeCallback.Invoke(netObj, new object[] { value });
                                }
                                else
                                {
                                    state.syncVarInfo.field.SetValue(netObj, value);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                        }
                    }
                    break;

                case Action_RequestSyncVar:
                    bits = reader.ReadUInt32();
                    break;
                }
            }
        }
Esempio n. 2
0
 public SyncVarMessage(NetworkObject netObj)
 {
     this.netObj = netObj;
 }