/// <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); } } } }
/// <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); } } } }
/// <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); } }
/// <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); } }
/// <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); } }
/// <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); } }
/// <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); }
/// <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); }
/// <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; } } } }