diff --git a/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkSet.cs b/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkSet.cs index 06dc63189f..9e0e58953f 100644 --- a/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkSet.cs +++ b/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkSet.cs @@ -331,29 +331,6 @@ IEnumerator IEnumerable.GetEnumerator() return m_Set.GetEnumerator(); } - /// - void ICollection.Add(T item) - { - EnsureInitialized(); - - if (m_NetworkBehaviour.NetworkManager.IsServer) - { - m_Set.Add(item); - } - - var setEvent = new NetworkSetEvent() - { - Type = NetworkSetEvent.EventType.Add, - Value = item - }; - m_DirtyEvents.Add(setEvent); - - if (m_NetworkBehaviour.NetworkManager.IsServer && OnSetChanged != null) - { - OnSetChanged(setEvent); - } - } - /// public void ExceptWith(IEnumerable other) { @@ -478,8 +455,7 @@ public void UnionWith(IEnumerable other) } } - /// - bool ISet.Add(T item) + public void Add(T item) { EnsureInitialized(); @@ -499,10 +475,21 @@ bool ISet.Add(T item) { OnSetChanged(setEvent); } + } + /// + bool ISet.Add(T item) + { + Add(item); return true; } + /// + void ICollection.Add(T item) + { + Add(item); + } + /// public void Clear() { diff --git a/com.unity.multiplayer.mlapi/Tests/Runtime/NetworkVariableTests.cs b/com.unity.multiplayer.mlapi/Tests/Runtime/NetworkVariableTests.cs index dd3cde9001..4b76e5645a 100644 --- a/com.unity.multiplayer.mlapi/Tests/Runtime/NetworkVariableTests.cs +++ b/com.unity.multiplayer.mlapi/Tests/Runtime/NetworkVariableTests.cs @@ -1,6 +1,5 @@ using System; using System.Collections; -using System.Collections.Generic; using UnityEngine; using UnityEngine.TestTools; using NUnit.Framework; @@ -101,6 +100,7 @@ public override IEnumerator Setup() // This is the *SERVER VERSION* of the *CLIENT PLAYER* var serverClientPlayerResult = new MultiInstanceHelpers.CoroutineResultWrapper(); + yield return MultiInstanceHelpers.Run(MultiInstanceHelpers.GetNetworkObjectByRepresentation( x => x.IsPlayerObject && x.OwnerClientId == m_ClientNetworkManagers[0].LocalClientId, m_ServerNetworkManager, serverClientPlayerResult)); @@ -118,14 +118,16 @@ public override IEnumerator Setup() m_ClientComp = clientSideClientPlayer.GetComponent(); m_ServerComp.TheList.Clear(); + m_ServerComp.TheSet.Clear(); + m_ServerComp.TheDictionary.Clear(); - if (m_ServerComp.TheList.Count > 0) + if (m_ServerComp.TheList.Count > 0 || m_ServerComp.TheSet.Count > 0 || m_ServerComp.TheDictionary.Count > 0) { - throw new Exception("server network list not empty at start"); + throw new Exception("at least one server network container not empty at start"); } - if (m_ClientComp.TheList.Count > 0) + if (m_ClientComp.TheList.Count > 0 || m_ClientComp.TheSet.Count > 0 || m_ClientComp.TheDictionary.Count > 0) { - throw new Exception("client network list not empty at start"); + throw new Exception("at least one client network container not empty at start"); } } @@ -178,8 +180,6 @@ public IEnumerator AllNetworkVariableTypes() [UnityTest] public IEnumerator NetworkListAdd() { - var waitResult = new MultiInstanceHelpers.CoroutineResultWrapper(); - yield return MultiInstanceHelpers.RunAndWaitForCondition( () => { @@ -245,9 +245,8 @@ public IEnumerator NetworkSetAdd() yield return MultiInstanceHelpers.RunAndWaitForCondition( () => { - ISet iSet = m_ServerComp.TheSet; - iSet.Add(k_TestVal1); - iSet.Add(k_TestVal2); + m_ServerComp.TheSet.Add(k_TestVal1); + m_ServerComp.TheSet.Add(k_TestVal2); }, () => { @@ -272,8 +271,7 @@ public IEnumerator NetworkSetRemove() yield return MultiInstanceHelpers.RunAndWaitForCondition( () => { - ISet iSet = m_ServerComp.TheSet; - iSet.Remove(k_TestVal1); + m_ServerComp.TheSet.Remove(k_TestVal1); }, () => { @@ -296,8 +294,7 @@ public IEnumerator NetworkSetClear() yield return MultiInstanceHelpers.RunAndWaitForCondition( () => { - ISet iSet = m_ServerComp.TheSet; - iSet.Clear(); + m_ServerComp.TheSet.Clear(); }, () => {