Beispiel #1
0
        void AddOperation(Operation op, int itemIndex, T item)
        {
            Change change = new Change
            {
                operation = op,
                index     = itemIndex,
                item      = item
            };

            Changes.Add(change);

            SyncListChanged listChanged = Callback;

            if (listChanged != null)
            {
                listChanged(op, itemIndex);
            }
        }
Beispiel #2
0
        void AddOperation(Operation op, int itemIndex, T item)
        {
            if (IsReadOnly)
            {
                throw new InvalidOperationException("Synclists can only be modified at the server");
            }

            Change change = new Change
            {
                operation = op,
                index     = itemIndex,
                item      = item
            };

            Changes.Add(change);

            SyncListChanged listChanged = Callback;

            if (listChanged != null)
            {
                listChanged(op, itemIndex, item);
            }
        }
Beispiel #3
0
        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;
                }

                SyncListChanged listChanged = Callback;
                if (apply && listChanged != null)
                {
                    listChanged(operation, index);
                }

                // we just skipped this change
                if (!apply)
                {
                    changesAhead--;
                }
            }
        }