コード例 #1
0
ファイル: Messages.cs プロジェクト: simonwittber/Mirror
 public override void Deserialize(NetworkReader reader)
 {
     netId        = reader.ReadNetworkId();
     syncListHash = reader.ReadInt32(); // hash is always 4 full bytes, WritePackedInt would send 1 extra byte here
     payload      = reader.ReadBytesAndSize();
 }
コード例 #2
0
ファイル: SyncList.cs プロジェクト: badangels88/Mirror
        public void OnDeserializeDelta(NetworkReader reader)
        {
            int changesCount = reader.ReadInt32();

            for (int i = 0; i < changesCount; i++)
            {
                Operation operation = (Operation)reader.ReadByte();

                // apply the operation only if it is a new change
                // that we have not applied yet
                bool apply = changesAhead == 0;
                int  index = 0;
                T    item;

                switch (operation)
                {
                case Operation.OP_ADD:
                    item = DeserializeItem(reader);
                    if (apply)
                    {
                        m_Objects.Add(item);
                    }
                    break;

                case Operation.OP_CLEAR:
                    if (apply)
                    {
                        m_Objects.Clear();
                    }
                    break;

                case Operation.OP_INSERT:
                    index = reader.ReadInt32();
                    item  = DeserializeItem(reader);
                    if (apply)
                    {
                        m_Objects.Insert(index, item);
                    }
                    break;

                case Operation.OP_REMOVE:
                    item = DeserializeItem(reader);
                    if (apply)
                    {
                        m_Objects.Remove(item);
                    }
                    break;

                case Operation.OP_REMOVEAT:
                    index = reader.ReadInt32();
                    if (apply)
                    {
                        m_Objects.RemoveAt(index);
                    }
                    break;

                case Operation.OP_SET:
                case Operation.OP_DIRTY:
                    index = reader.ReadInt32();
                    item  = DeserializeItem(reader);
                    if (apply)
                    {
                        m_Objects[index] = item;
                    }
                    break;
                }

                if (m_Callback != null && apply)
                {
                    m_Callback.Invoke(operation, index);
                }

                // we just skipped this change
                if (!apply)
                {
                    changesAhead--;
                }
            }
        }
コード例 #3
0
        public void OnDeserializeDelta(NetworkReader reader)
        {
            // This list can now only be modified by synchronization
            _isReadOnly = true;

            int changesCount = reader.ReadInt32();

            for (int i = 0; i < changesCount; i++)
            {
                Operation operation = (Operation)reader.ReadByte();

                // apply the operation only if it is a new change
                // that we have not applied yet
                bool apply = changesAhead == 0;
                int  index = 0;
                T    item  = default(T);

                switch (operation)
                {
                case Operation.OP_ADD:
                    item = DeserializeItem(reader);
                    if (apply)
                    {
                        index = m_Objects.Count;
                        m_Objects.Add(item);
                    }
                    break;

                case Operation.OP_CLEAR:
                    if (apply)
                    {
                        m_Objects.Clear();
                    }
                    break;

                case Operation.OP_INSERT:
                    index = (int)reader.ReadPackedUInt32();
                    item  = DeserializeItem(reader);
                    if (apply)
                    {
                        m_Objects.Insert(index, item);
                    }
                    break;

                case Operation.OP_REMOVE:
                    item = DeserializeItem(reader);
                    if (apply)
                    {
                        m_Objects.Remove(item);
                    }
                    break;

                case Operation.OP_REMOVEAT:
                    index = (int)reader.ReadPackedUInt32();
                    if (apply)
                    {
                        item = m_Objects[index];
                        m_Objects.RemoveAt(index);
                    }
                    break;

                case Operation.OP_SET:
                case Operation.OP_DIRTY:
                    index = (int)reader.ReadPackedUInt32();
                    item  = DeserializeItem(reader);
                    if (apply)
                    {
                        m_Objects[index] = item;
                    }
                    break;
                }

                if (apply)
                {
                    Callback?.Invoke(operation, index, item);
                }
                // we just skipped this change
                else
                {
                    changesAhead--;
                }
            }
        }
コード例 #4
0
 public override void OnDeserialize(NetworkReader reader, bool initialState)
 {
     value = reader.ReadInt32();
 }