Example #1
0
        /// <inheritdoc />
        public T this[int index]
        {
            get
            {
                return(list[index]);
            }
            set
            {
                if (NetworkingManager.Singleton.IsServer)
                {
                    list[index] = value;
                }

                NetworkedListEvent <T> listEvent = new NetworkedListEvent <T>()
                {
                    eventType = NetworkedListEvent <T> .EventType.Value,
                    index     = index,
                    value     = value
                };
                dirtyEvents.Add(listEvent);

                if (NetworkingManager.Singleton.IsServer && OnListChanged != null)
                {
                    OnListChanged(listEvent);
                }
            }
        }
Example #2
0
        /// <inheritdoc />
        public void Clear()
        {
            if (NetworkingManager.Singleton.IsServer)
            {
                list.Clear();
            }

            NetworkedListEvent <T> listEvent = new NetworkedListEvent <T>()
            {
                eventType = NetworkedListEvent <T> .EventType.Clear
            };

            HandleAddListEvent(listEvent);
        }
Example #3
0
        /// <inheritdoc />
        public void RemoveAt(int index)
        {
            if (NetworkingManager.Singleton.IsServer)
            {
                list.RemoveAt(index);
            }

            NetworkedListEvent <T> listEvent = new NetworkedListEvent <T>()
            {
                eventType = NetworkedListEvent <T> .EventType.RemoveAt,
                index     = index
            };

            HandleAddListEvent(listEvent);
        }
Example #4
0
        /// <inheritdoc />
        public void Clear()
        {
            list.Clear();
            NetworkedListEvent <T> listEvent = new NetworkedListEvent <T>()
            {
                eventType = NetworkedListEvent <T> .EventType.Clear
            };

            dirtyEvents.Add(listEvent);

            if (OnListChanged != null)
            {
                OnListChanged(listEvent);
            }
        }
Example #5
0
        /// <inheritdoc />
        public void Add(T item)
        {
            if (NetworkingManager.Singleton.IsServer)
            {
                list.Add(item);
            }

            NetworkedListEvent <T> listEvent = new NetworkedListEvent <T>()
            {
                eventType = NetworkedListEvent <T> .EventType.Add,
                value     = item,
                index     = list.Count - 1
            };

            HandleAddListEvent(listEvent);
        }
Example #6
0
        private void HandleAddListEvent(NetworkedListEvent <T> listEvent)
        {
            if (NetworkingManager.Singleton.IsServer)
            {
                if (NetworkingManager.Singleton.ConnectedClients.Count > 0)
                {
                    dirtyEvents.Add(listEvent);
                }

                OnListChanged?.Invoke(listEvent);
            }
            else
            {
                dirtyEvents.Add(listEvent);
            }
        }
Example #7
0
        /// <inheritdoc />
        public void Insert(int index, T item)
        {
            if (NetworkingManager.Singleton.IsServer)
            {
                list.Insert(index, item);
            }

            NetworkedListEvent <T> listEvent = new NetworkedListEvent <T>()
            {
                eventType = NetworkedListEvent <T> .EventType.Insert,
                index     = index,
                value     = item
            };

            HandleAddListEvent(listEvent);
        }
Example #8
0
        /// <inheritdoc />
        public bool Remove(T item)
        {
            if (NetworkingManager.Singleton.IsServer)
            {
                list.Remove(item);
            }

            NetworkedListEvent <T> listEvent = new NetworkedListEvent <T>()
            {
                eventType = NetworkedListEvent <T> .EventType.Remove,
                value     = item
            };

            HandleAddListEvent(listEvent);
            return(true);
        }
Example #9
0
        /// <inheritdoc />
        public void Insert(int index, T item)
        {
            list.Insert(index, item);
            NetworkedListEvent <T> listEvent = new NetworkedListEvent <T>()
            {
                eventType = NetworkedListEvent <T> .EventType.Insert,
                index     = index,
                value     = item
            };

            dirtyEvents.Add(listEvent);

            if (OnListChanged != null)
            {
                OnListChanged(listEvent);
            }
        }
Example #10
0
        /// <inheritdoc />
        public void Add(T item)
        {
            list.Add(item);
            NetworkedListEvent <T> listEvent = new NetworkedListEvent <T>()
            {
                eventType = NetworkedListEvent <T> .EventType.Add,
                value     = item,
                index     = list.Count - 1
            };

            dirtyEvents.Add(listEvent);

            if (OnListChanged != null)
            {
                OnListChanged(listEvent);
            }
        }
Example #11
0
        /// <inheritdoc />
        public void RemoveAt(int index)
        {
            T value = list[index];

            list.RemoveAt(index);
            NetworkedListEvent <T> listEvent = new NetworkedListEvent <T>()
            {
                eventType = NetworkedListEvent <T> .EventType.RemoveAt,
                index     = index,
                value     = value
            };

            dirtyEvents.Add(listEvent);

            if (OnListChanged != null)
            {
                OnListChanged(listEvent);
            }
        }
Example #12
0
        /// <inheritdoc />
        public void Clear()
        {
            if (NetworkManager.Get().isServer)
            {
                list.Clear();
            }

            NetworkedListEvent <T> listEvent = new NetworkedListEvent <T>()
            {
                eventType = NetworkedListEvent <T> .EventType.Clear
            };

            dirtyEvents.Add(listEvent);

            if (NetworkManager.Get().isServer&& OnListChanged != null)
            {
                OnListChanged(listEvent);
            }
        }
Example #13
0
        /// <inheritdoc />
        public bool Remove(T item)
        {
            bool state = list.Remove(item);

            if (state)
            {
                NetworkedListEvent <T> listEvent = new NetworkedListEvent <T>()
                {
                    eventType = NetworkedListEvent <T> .EventType.Remove,
                    value     = item
                };
                dirtyEvents.Add(listEvent);

                if (OnListChanged != null)
                {
                    OnListChanged(listEvent);
                }
            }
            return(state);
        }
Example #14
0
        /// <inheritdoc />
        public T this[int index]
        {
            get { return(list[index]); }
            set
            {
                if (NetworkingManager.Singleton.IsServer)
                {
                    list[index] = value;
                }

                NetworkedListEvent <T> listEvent = new NetworkedListEvent <T>()
                {
                    eventType = NetworkedListEvent <T> .EventType.Value,
                    index     = index,
                    value     = value
                };

                HandleAddListEvent(listEvent);
            }
        }
Example #15
0
        /// <inheritdoc />
        public void RemoveAt(int index)
        {
            if (NetworkManager.Get().isServer)
            {
                list.RemoveAt(index);
            }

            NetworkedListEvent <T> listEvent = new NetworkedListEvent <T>()
            {
                eventType = NetworkedListEvent <T> .EventType.RemoveAt,
                index     = index
            };

            dirtyEvents.Add(listEvent);

            if (NetworkManager.Get().isServer&& OnListChanged != null)
            {
                OnListChanged(listEvent);
            }
        }
Example #16
0
        /// <inheritdoc />
        public void Insert(int index, T item)
        {
            if (NetworkManager.Get().isServer)
            {
                list.Insert(index, item);
            }

            NetworkedListEvent <T> listEvent = new NetworkedListEvent <T>()
            {
                eventType = NetworkedListEvent <T> .EventType.Insert,
                index     = index,
                value     = item
            };

            dirtyEvents.Add(listEvent);

            if (NetworkManager.Get().isServer&& OnListChanged != null)
            {
                OnListChanged(listEvent);
            }
        }
Example #17
0
        /// <inheritdoc />
        public void Add(T item)
        {
            if (NetworkManager.Get().isServer)
            {
                list.Add(item);
            }

            NetworkedListEvent <T> listEvent = new NetworkedListEvent <T>()
            {
                eventType = NetworkedListEvent <T> .EventType.Add,
                value     = item,
                index     = list.Count - 1
            };

            dirtyEvents.Add(listEvent);

            if (NetworkManager.Get().isServer&& OnListChanged != null)
            {
                OnListChanged(listEvent);
            }
        }
Example #18
0
        /// <inheritdoc />
        public bool Remove(T item)
        {
            if (NetworkManager.Get().isServer)
            {
                list.Remove(item);
            }

            NetworkedListEvent <T> listEvent = new NetworkedListEvent <T>()
            {
                eventType = NetworkedListEvent <T> .EventType.Remove,
                value     = item
            };

            dirtyEvents.Add(listEvent);

            if (NetworkManager.Get().isServer&& OnListChanged != null)
            {
                OnListChanged(listEvent);
            }

            return(true);
        }
Example #19
0
        /// <inheritdoc />
        public T this[int index]
        {
            get
            {
                return(list[index]);
            }
            set
            {
                list[index] = value;
                NetworkedListEvent <T> listEvent = new NetworkedListEvent <T>()
                {
                    eventType = NetworkedListEvent <T> .EventType.Value,
                    index     = index,
                    value     = value
                };
                dirtyEvents.Add(listEvent);

                if (OnListChanged != null)
                {
                    OnListChanged(listEvent);
                }
            }
        }
Example #20
0
 private void onPlayersChanged(MLAPI.NetworkedVar.Collections.NetworkedListEvent <NetworkPlayer> changeEvent)
 {
     refreshPlayerList();
 }
Example #21
0
        /// <inheritdoc />
        public void ReadDelta(Stream stream, bool keepDirtyDelta)
        {
            using (PooledBitReader reader = PooledBitReader.Get(stream))
            {
                ushort deltaCount = reader.ReadUInt16Packed();
                for (int i = 0; i < deltaCount; i++)
                {
                    NetworkedListEvent <T> .EventType eventType = (NetworkedListEvent <T> .EventType)reader.ReadBits(3);
                    switch (eventType)
                    {
                    case NetworkedListEvent <T> .EventType.Add:
                    {
                        list.Add((T)reader.ReadObjectPacked(typeof(T)));         //BOX

                        if (OnListChanged != null)
                        {
                            OnListChanged(new NetworkedListEvent <T>
                                {
                                    eventType = eventType,
                                    index     = list.Count - 1,
                                    value     = list[list.Count - 1]
                                });
                        }

                        if (keepDirtyDelta)
                        {
                            dirtyEvents.Add(new NetworkedListEvent <T>()
                                {
                                    eventType = eventType,
                                    index     = list.Count - 1,
                                    value     = list[list.Count - 1]
                                });
                        }
                    }
                    break;

                    case NetworkedListEvent <T> .EventType.Insert:
                    {
                        int index = reader.ReadInt32Packed();
                        list.Insert(index, (T)reader.ReadObjectPacked(typeof(T)));         //BOX

                        if (OnListChanged != null)
                        {
                            OnListChanged(new NetworkedListEvent <T>
                                {
                                    eventType = eventType,
                                    index     = index,
                                    value     = list[index]
                                });
                        }

                        if (keepDirtyDelta)
                        {
                            dirtyEvents.Add(new NetworkedListEvent <T>()
                                {
                                    eventType = eventType,
                                    index     = index,
                                    value     = list[index]
                                });
                        }
                    }
                    break;

                    case NetworkedListEvent <T> .EventType.Remove:
                    {
                        T   value = (T)reader.ReadObjectPacked(typeof(T));       //BOX
                        int index = list.IndexOf(value);
                        list.RemoveAt(index);

                        if (OnListChanged != null)
                        {
                            OnListChanged(new NetworkedListEvent <T>
                                {
                                    eventType = eventType,
                                    index     = index,
                                    value     = value
                                });
                        }

                        if (keepDirtyDelta)
                        {
                            dirtyEvents.Add(new NetworkedListEvent <T>()
                                {
                                    eventType = eventType,
                                    index     = index,
                                    value     = value
                                });
                        }
                    }
                    break;

                    case NetworkedListEvent <T> .EventType.RemoveAt:
                    {
                        int index = reader.ReadInt32Packed();
                        T   value = list[index];
                        list.RemoveAt(index);

                        if (OnListChanged != null)
                        {
                            OnListChanged(new NetworkedListEvent <T>
                                {
                                    eventType = eventType,
                                    index     = index,
                                    value     = value
                                });
                        }

                        if (keepDirtyDelta)
                        {
                            dirtyEvents.Add(new NetworkedListEvent <T>()
                                {
                                    eventType = eventType,
                                    index     = index,
                                    value     = value
                                });
                        }
                    }
                    break;

                    case NetworkedListEvent <T> .EventType.Value:
                    {
                        int index = reader.ReadInt32Packed();
                        T   value = (T)reader.ReadObjectPacked(typeof(T));       //BOX
                        if (index < list.Count)
                        {
                            list[index] = value;
                        }

                        if (OnListChanged != null)
                        {
                            OnListChanged(new NetworkedListEvent <T>
                                {
                                    eventType = eventType,
                                    index     = index,
                                    value     = value
                                });
                        }

                        if (keepDirtyDelta)
                        {
                            dirtyEvents.Add(new NetworkedListEvent <T>()
                                {
                                    eventType = eventType,
                                    index     = index,
                                    value     = value
                                });
                        }
                    }
                    break;

                    case NetworkedListEvent <T> .EventType.Clear:
                    {
                        //Read nothing
                        list.Clear();

                        if (OnListChanged != null)
                        {
                            OnListChanged(new NetworkedListEvent <T>
                                {
                                    eventType = eventType,
                                });
                        }

                        if (keepDirtyDelta)
                        {
                            dirtyEvents.Add(new NetworkedListEvent <T>()
                                {
                                    eventType = eventType
                                });
                        }
                    }
                    break;
                    }
                }
            }
        }