예제 #1
0
        public void OnDeserializeDelta(NetworkReader reader)
        {
            // This list can now only be modified by synchronization
            IsReadOnly = true;
            bool raiseOnChange = false;

            int changesCount = (int)reader.ReadPackedUInt32();

            for (int i = 0; i < changesCount; i++)
            {
                var 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    oldItem = default;
                T    newItem = default;

                switch (operation)
                {
                case Operation.OP_ADD:
                    newItem = reader.Read <T>();
                    if (apply)
                    {
                        index = objects.Count;
                        objects.Add(newItem);
                    }
                    break;

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

                case Operation.OP_INSERT:
                    index   = (int)reader.ReadPackedUInt32();
                    newItem = reader.Read <T>();
                    if (apply)
                    {
                        objects.Insert(index, newItem);
                    }
                    break;

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

                case Operation.OP_SET:
                    index   = (int)reader.ReadPackedUInt32();
                    newItem = reader.Read <T>();
                    if (apply)
                    {
                        oldItem        = objects[index];
                        objects[index] = newItem;
                    }
                    break;
                }

                if (apply)
                {
                    RaiseEvents(operation, index, oldItem, newItem);
                    raiseOnChange = true;
                }
                // we just skipped this change
                else
                {
                    changesAhead--;
                }
            }

            if (raiseOnChange)
            {
                OnChange?.Invoke();
            }
        }
예제 #2
0
파일: Messages.cs 프로젝트: jaeger25/Mirror
 public override void Deserialize(NetworkReader reader)
 {
     value = (int)reader.ReadPackedUInt32();
 }
예제 #3
0
파일: Messages.cs 프로젝트: jaeger25/Mirror
 public override void Deserialize(NetworkReader reader)
 {
     netId = reader.ReadPackedUInt32();
     hash  = (int)reader.ReadPackedUInt32();
 }
예제 #4
0
파일: Messages.cs 프로젝트: jaeger25/Mirror
 public override void Deserialize(NetworkReader reader)
 {
     netId   = reader.ReadPackedUInt32();
     payload = reader.ReadBytesAndSize();
 }
예제 #5
0
파일: Messages.cs 프로젝트: jaeger25/Mirror
 public override void Deserialize(NetworkReader reader)
 {
     netId     = reader.ReadPackedUInt32();
     authority = reader.ReadBoolean();
 }