コード例 #1
0
        /// <inheritdoc />
        public void UnionWith(IEnumerable <T> other)
        {
            foreach (T value in other)
            {
                if (!m_Set.Contains(value))
                {
                    if (NetworkManager.Singleton.IsServer)
                    {
                        m_Set.Add(value);
                    }

                    NetworkSetEvent <T> setEvent = new NetworkSetEvent <T>()
                    {
                        Type  = NetworkSetEvent <T> .EventType.Add,
                        Value = value
                    };
                    m_DirtyEvents.Add(setEvent);

                    if (NetworkManager.Singleton.IsServer && OnSetChanged != null)
                    {
                        OnSetChanged(setEvent);
                    }
                }
            }
        }
コード例 #2
0
        /// <inheritdoc />
        public void UnionWith(IEnumerable <T> other)
        {
            EnsureInitialized();

            foreach (T value in other)
            {
                if (!m_Set.Contains(value))
                {
                    if (m_NetworkBehaviour.NetworkManager.IsServer)
                    {
                        m_Set.Add(value);
                    }

                    var setEvent = new NetworkSetEvent <T>()
                    {
                        Type  = NetworkSetEvent <T> .EventType.Add,
                        Value = value
                    };
                    m_DirtyEvents.Add(setEvent);

                    if (m_NetworkBehaviour.NetworkManager.IsServer && OnSetChanged != null)
                    {
                        OnSetChanged(setEvent);
                    }
                }
            }
        }
コード例 #3
0
        /// <inheritdoc />
        public void Clear()
        {
            if (NetworkManager.Singleton.IsServer)
            {
                m_Set.Clear();
            }

            NetworkSetEvent <T> setEvent = new NetworkSetEvent <T>()
            {
                Type = NetworkSetEvent <T> .EventType.Clear
            };

            m_DirtyEvents.Add(setEvent);

            if (NetworkManager.Singleton.IsServer && OnSetChanged != null)
            {
                OnSetChanged(setEvent);
            }
        }
コード例 #4
0
        /// <inheritdoc />
        void ICollection <T> .Add(T item)
        {
            if (NetworkManager.Singleton.IsServer)
            {
                m_Set.Add(item);
            }

            NetworkSetEvent <T> setEvent = new NetworkSetEvent <T>()
            {
                Type  = NetworkSetEvent <T> .EventType.Add,
                Value = item
            };

            m_DirtyEvents.Add(setEvent);

            if (NetworkManager.Singleton.IsServer && OnSetChanged != null)
            {
                OnSetChanged(setEvent);
            }
        }
コード例 #5
0
        /// <inheritdoc />
        public void Clear()
        {
            EnsureInitialized();

            if (m_NetworkBehaviour.NetworkManager.IsServer)
            {
                m_Set.Clear();
            }

            var setEvent = new NetworkSetEvent <T>()
            {
                Type = NetworkSetEvent <T> .EventType.Clear
            };

            m_DirtyEvents.Add(setEvent);

            if (m_NetworkBehaviour.NetworkManager.IsServer && OnSetChanged != null)
            {
                OnSetChanged(setEvent);
            }
        }
コード例 #6
0
        /// <inheritdoc />
        void ICollection <T> .Add(T item)
        {
            EnsureInitialized();

            if (m_NetworkBehaviour.NetworkManager.IsServer)
            {
                m_Set.Add(item);
            }

            var setEvent = new NetworkSetEvent <T>()
            {
                Type  = NetworkSetEvent <T> .EventType.Add,
                Value = item
            };

            m_DirtyEvents.Add(setEvent);

            if (m_NetworkBehaviour.NetworkManager.IsServer && OnSetChanged != null)
            {
                OnSetChanged(setEvent);
            }
        }
コード例 #7
0
        /// <inheritdoc />
        public bool Remove(T item)
        {
            if (NetworkManager.Singleton.IsServer)
            {
                m_Set.Remove(item);
            }

            NetworkSetEvent <T> setEvent = new NetworkSetEvent <T>()
            {
                Type  = NetworkSetEvent <T> .EventType.Remove,
                Value = item
            };

            m_DirtyEvents.Add(setEvent);

            if (NetworkManager.Singleton.IsServer && OnSetChanged != null)
            {
                OnSetChanged(setEvent);
            }

            return(true);
        }
コード例 #8
0
        /// <inheritdoc />
        public bool Remove(T item)
        {
            EnsureInitialized();

            if (m_NetworkBehaviour.NetworkManager.IsServer)
            {
                m_Set.Remove(item);
            }

            var setEvent = new NetworkSetEvent <T>()
            {
                Type  = NetworkSetEvent <T> .EventType.Remove,
                Value = item
            };

            m_DirtyEvents.Add(setEvent);

            if (m_NetworkBehaviour.NetworkManager.IsServer && OnSetChanged != null)
            {
                OnSetChanged(setEvent);
            }

            return(true);
        }
コード例 #9
0
        /// <inheritdoc />
        public void ReadDelta(Stream stream, bool keepDirtyDelta, ushort localTick, ushort remoteTick)
        {
            using (var reader = PooledNetworkReader.Get(stream))
            {
                ushort deltaCount = reader.ReadUInt16Packed();
                for (int i = 0; i < deltaCount; i++)
                {
                    NetworkSetEvent <T> .EventType eventType = (NetworkSetEvent <T> .EventType)reader.ReadBits(2);
                    switch (eventType)
                    {
                    case NetworkSetEvent <T> .EventType.Add:
                    {
                        T value = (T)reader.ReadObjectPacked(typeof(T));     //BOX
                        m_Set.Add(value);

                        if (OnSetChanged != null)
                        {
                            OnSetChanged(new NetworkSetEvent <T>
                                {
                                    Type  = eventType,
                                    Value = value
                                });
                        }

                        if (keepDirtyDelta)
                        {
                            m_DirtyEvents.Add(new NetworkSetEvent <T>()
                                {
                                    Type  = eventType,
                                    Value = value
                                });
                        }
                    }
                    break;

                    case NetworkSetEvent <T> .EventType.Remove:
                    {
                        T value = (T)reader.ReadObjectPacked(typeof(T));     //BOX
                        m_Set.Remove(value);

                        if (OnSetChanged != null)
                        {
                            OnSetChanged(new NetworkSetEvent <T>
                                {
                                    Type  = eventType,
                                    Value = value
                                });
                        }

                        if (keepDirtyDelta)
                        {
                            m_DirtyEvents.Add(new NetworkSetEvent <T>()
                                {
                                    Type  = eventType,
                                    Value = value
                                });
                        }
                    }
                    break;

                    case NetworkSetEvent <T> .EventType.Clear:
                    {
                        //Read nothing
                        m_Set.Clear();

                        if (OnSetChanged != null)
                        {
                            OnSetChanged(new NetworkSetEvent <T>
                                {
                                    Type = eventType,
                                });
                        }

                        if (keepDirtyDelta)
                        {
                            m_DirtyEvents.Add(new NetworkSetEvent <T>()
                                {
                                    Type = eventType
                                });
                        }
                    }
                    break;
                    }
                }
            }
        }