From d89881528b5296cbe313c253006fc3a760506f6a Mon Sep 17 00:00:00 2001 From: Benoit Doyon Date: Mon, 7 Jun 2021 13:53:44 -0400 Subject: [PATCH 1/9] Add name property for network variables, set during initialization by reflection --- com.unity.multiplayer.mlapi/Runtime/Core/NetworkBehaviour.cs | 1 + .../Runtime/NetworkVariable/Collections/NetworkDictionary.cs | 2 ++ .../Runtime/NetworkVariable/Collections/NetworkList.cs | 2 ++ .../Runtime/NetworkVariable/Collections/NetworkSet.cs | 2 ++ .../Runtime/NetworkVariable/INetworkVariable.cs | 1 + .../Runtime/NetworkVariable/NetworkVariable.cs | 2 ++ 6 files changed, 10 insertions(+) diff --git a/com.unity.multiplayer.mlapi/Runtime/Core/NetworkBehaviour.cs b/com.unity.multiplayer.mlapi/Runtime/Core/NetworkBehaviour.cs index f1638fb95d..182619d33e 100644 --- a/com.unity.multiplayer.mlapi/Runtime/Core/NetworkBehaviour.cs +++ b/com.unity.multiplayer.mlapi/Runtime/Core/NetworkBehaviour.cs @@ -444,6 +444,7 @@ internal void InitializeVariables() } instance.SetNetworkBehaviour(this); + instance.Name = sortedFields[i].Name; NetworkVariableFields.Add(instance); } } diff --git a/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkDictionary.cs b/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkDictionary.cs index 807379fbe3..a83eea92d5 100644 --- a/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkDictionary.cs +++ b/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkDictionary.cs @@ -74,6 +74,8 @@ public NetworkDictionary(IDictionary value) m_Dictionary = value; } + public string Name { get; set; } + /// public void ResetDirty() { diff --git a/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkList.cs b/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkList.cs index b204cc8ba2..c53c76d5b1 100644 --- a/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkList.cs +++ b/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkList.cs @@ -72,6 +72,8 @@ public NetworkList(IList value) m_List = value; } + public string Name { get; set; } + /// public void ResetDirty() { diff --git a/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkSet.cs b/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkSet.cs index 429856d8d6..450ccfa4dd 100644 --- a/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkSet.cs +++ b/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkSet.cs @@ -73,6 +73,8 @@ public NetworkSet(ISet value) m_Set = value; } + public string Name { get; set; } + /// public void ResetDirty() { diff --git a/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/INetworkVariable.cs b/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/INetworkVariable.cs index 41f3538538..a546711eb0 100644 --- a/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/INetworkVariable.cs +++ b/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/INetworkVariable.cs @@ -74,5 +74,6 @@ public interface INetworkVariable /// The behaviour the container behaves to void SetNetworkBehaviour(NetworkBehaviour behaviour); + string Name { get; set; } } } diff --git a/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/NetworkVariable.cs b/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/NetworkVariable.cs index 42016b0e77..21694943fc 100644 --- a/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/NetworkVariable.cs +++ b/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/NetworkVariable.cs @@ -90,6 +90,8 @@ public T Value private bool m_IsDirty = false; + public string Name { get; set; } + /// /// Sets whether or not the variable needs to be delta synced /// From 93362afd3f8e765d006d8eaf051090efc9b53b21 Mon Sep 17 00:00:00 2001 From: Benoit Doyon Date: Mon, 7 Jun 2021 14:05:22 -0400 Subject: [PATCH 2/9] Add XML doc --- .../NetworkVariable/Collections/NetworkDictionary.cs | 4 ++++ .../Runtime/NetworkVariable/Collections/NetworkSet.cs | 4 ++++ .../Runtime/NetworkVariable/INetworkVariable.cs | 8 ++++++-- .../Runtime/NetworkVariable/NetworkVariable.cs | 4 ++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkDictionary.cs b/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkDictionary.cs index a83eea92d5..e0c9c22656 100644 --- a/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkDictionary.cs +++ b/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkDictionary.cs @@ -74,6 +74,10 @@ public NetworkDictionary(IDictionary value) m_Dictionary = value; } + /// + /// Gets or sets the name of the network variable's instance + /// (MemberInfo) where it was declared. + /// public string Name { get; set; } /// diff --git a/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkSet.cs b/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkSet.cs index 450ccfa4dd..652a147e35 100644 --- a/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkSet.cs +++ b/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkSet.cs @@ -73,6 +73,10 @@ public NetworkSet(ISet value) m_Set = value; } + /// + /// Gets or sets the name of the network variable's instance + /// (MemberInfo) where it was declared. + /// public string Name { get; set; } /// diff --git a/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/INetworkVariable.cs b/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/INetworkVariable.cs index a546711eb0..0fc644ab16 100644 --- a/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/INetworkVariable.cs +++ b/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/INetworkVariable.cs @@ -8,6 +8,12 @@ namespace MLAPI.NetworkVariable /// public interface INetworkVariable { + /// + /// Gets or sets the name of the network variable's instance + /// (MemberInfo) where it was declared. + /// + string Name { get; set; } + /// /// Returns the name of the channel to be used for syncing /// @@ -73,7 +79,5 @@ public interface INetworkVariable /// /// The behaviour the container behaves to void SetNetworkBehaviour(NetworkBehaviour behaviour); - - string Name { get; set; } } } diff --git a/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/NetworkVariable.cs b/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/NetworkVariable.cs index 21694943fc..1ca3042807 100644 --- a/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/NetworkVariable.cs +++ b/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/NetworkVariable.cs @@ -90,6 +90,10 @@ public T Value private bool m_IsDirty = false; + /// + /// Gets or sets the name of the network variable's instance + /// (MemberInfo) where it was declared. + /// public string Name { get; set; } /// From 315ccfe26c4c1add6f7833c1073eb0477fee15a9 Mon Sep 17 00:00:00 2001 From: Benoit Doyon Date: Tue, 8 Jun 2021 14:23:08 -0400 Subject: [PATCH 3/9] Make NetworkVariable name setter internal, add tests --- .../Runtime/Core/NetworkBehaviour.cs | 5 +- .../Collections/NetworkDictionary.cs | 2 +- .../Collections/NetworkList.cs | 2 +- .../NetworkVariable/Collections/NetworkSet.cs | 2 +- .../NetworkVariable/INetworkVariable.cs | 2 +- .../NetworkVariable/NetworkVariable.cs | 2 +- .../Tests/Runtime/Profiling.meta | 8 +++ .../Profiling/NetworkVariableNameTests.cs | 53 +++++++++++++++++++ .../NetworkVariableNameTests.cs.meta | 11 ++++ 9 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 com.unity.multiplayer.mlapi/Tests/Runtime/Profiling.meta create mode 100644 com.unity.multiplayer.mlapi/Tests/Runtime/Profiling/NetworkVariableNameTests.cs create mode 100644 com.unity.multiplayer.mlapi/Tests/Runtime/Profiling/NetworkVariableNameTests.cs.meta diff --git a/com.unity.multiplayer.mlapi/Runtime/Core/NetworkBehaviour.cs b/com.unity.multiplayer.mlapi/Runtime/Core/NetworkBehaviour.cs index 182619d33e..fd75dfb4e9 100644 --- a/com.unity.multiplayer.mlapi/Runtime/Core/NetworkBehaviour.cs +++ b/com.unity.multiplayer.mlapi/Runtime/Core/NetworkBehaviour.cs @@ -444,7 +444,10 @@ internal void InitializeVariables() } instance.SetNetworkBehaviour(this); - instance.Name = sortedFields[i].Name; + + var instanceNameProperty = instance.GetType().GetProperty(nameof(INetworkVariable.Name)); + instanceNameProperty?.SetValue(instance, sortedFields[i].Name); + NetworkVariableFields.Add(instance); } } diff --git a/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkDictionary.cs b/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkDictionary.cs index e0c9c22656..a6cf76b3d0 100644 --- a/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkDictionary.cs +++ b/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkDictionary.cs @@ -78,7 +78,7 @@ public NetworkDictionary(IDictionary value) /// Gets or sets the name of the network variable's instance /// (MemberInfo) where it was declared. /// - public string Name { get; set; } + public string Name { get; internal set; } /// public void ResetDirty() diff --git a/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkList.cs b/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkList.cs index c53c76d5b1..a391812395 100644 --- a/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkList.cs +++ b/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkList.cs @@ -72,7 +72,7 @@ public NetworkList(IList value) m_List = value; } - public string Name { get; set; } + public string Name { get; internal set; } /// public void ResetDirty() diff --git a/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkSet.cs b/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkSet.cs index 652a147e35..4b3675766c 100644 --- a/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkSet.cs +++ b/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/Collections/NetworkSet.cs @@ -77,7 +77,7 @@ public NetworkSet(ISet value) /// Gets or sets the name of the network variable's instance /// (MemberInfo) where it was declared. /// - public string Name { get; set; } + public string Name { get; internal set; } /// public void ResetDirty() diff --git a/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/INetworkVariable.cs b/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/INetworkVariable.cs index 0fc644ab16..f999c44eda 100644 --- a/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/INetworkVariable.cs +++ b/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/INetworkVariable.cs @@ -12,7 +12,7 @@ public interface INetworkVariable /// Gets or sets the name of the network variable's instance /// (MemberInfo) where it was declared. /// - string Name { get; set; } + string Name { get; } /// /// Returns the name of the channel to be used for syncing diff --git a/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/NetworkVariable.cs b/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/NetworkVariable.cs index 1ca3042807..f337e018f9 100644 --- a/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/NetworkVariable.cs +++ b/com.unity.multiplayer.mlapi/Runtime/NetworkVariable/NetworkVariable.cs @@ -94,7 +94,7 @@ public T Value /// Gets or sets the name of the network variable's instance /// (MemberInfo) where it was declared. /// - public string Name { get; set; } + public string Name { get; internal set; } /// /// Sets whether or not the variable needs to be delta synced diff --git a/com.unity.multiplayer.mlapi/Tests/Runtime/Profiling.meta b/com.unity.multiplayer.mlapi/Tests/Runtime/Profiling.meta new file mode 100644 index 0000000000..617845c000 --- /dev/null +++ b/com.unity.multiplayer.mlapi/Tests/Runtime/Profiling.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6b613c8dd4ba7d046b62971a3cb631ed +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.multiplayer.mlapi/Tests/Runtime/Profiling/NetworkVariableNameTests.cs b/com.unity.multiplayer.mlapi/Tests/Runtime/Profiling/NetworkVariableNameTests.cs new file mode 100644 index 0000000000..2ef7be7994 --- /dev/null +++ b/com.unity.multiplayer.mlapi/Tests/Runtime/Profiling/NetworkVariableNameTests.cs @@ -0,0 +1,53 @@ +using System; +using MLAPI.NetworkVariable; +using MLAPI.NetworkVariable.Collections; +using NUnit.Framework; + +namespace MLAPI.RuntimeTests.Profiling +{ + public sealed class NetworkVariableNameTests + { + NetworkManager m_NetworkManager; + NetworkVariableNameComponent m_NetworkVariableNameComponent; + + [SetUp] + public void SetUp() + { + NetworkManagerHelper.StartNetworkManager(out m_NetworkManager); + + var gameObjectId = NetworkManagerHelper.AddGameNetworkObject(Guid.NewGuid().ToString()); + m_NetworkVariableNameComponent= NetworkManagerHelper.AddComponentToObject(gameObjectId); + NetworkManagerHelper.SpawnNetworkObject(gameObjectId); + } + + [TearDown] + public void TearDown() + { + NetworkManagerHelper.ShutdownNetworkManager(); + } + + [Test] + public void EnsureNetworkVariableNameInitialization() + { + Assert.True(m_NetworkVariableNameComponent.NetworkVarString.Name.Contains(nameof(NetworkVariableNameComponent.NetworkVarString))); + Assert.True(m_NetworkVariableNameComponent.NetworkVarSet.Name.Contains(nameof(NetworkVariableNameComponent.NetworkVarSet))); + Assert.True(m_NetworkVariableNameComponent.NetworkVarList.Name.Contains(nameof(NetworkVariableNameComponent.NetworkVarList))); + Assert.True(m_NetworkVariableNameComponent.NetworkVarDictionary.Name.Contains(nameof(NetworkVariableNameComponent.NetworkVarDictionary))); + } + + private class NetworkVariableNameComponent : NetworkBehaviour + { + public NetworkVariableString NetworkVarString { get; } = new NetworkVariableString(); + + public NetworkSet NetworkVarSet { get; } = new NetworkSet(); + + public NetworkList NetworkVarList { get; } = new NetworkList(); + + public NetworkDictionary NetworkVarDictionary { get; } = new NetworkDictionary(); + } + } + + public class NetworkMetrics + { + } +} \ No newline at end of file diff --git a/com.unity.multiplayer.mlapi/Tests/Runtime/Profiling/NetworkVariableNameTests.cs.meta b/com.unity.multiplayer.mlapi/Tests/Runtime/Profiling/NetworkVariableNameTests.cs.meta new file mode 100644 index 0000000000..6ddaf9dffb --- /dev/null +++ b/com.unity.multiplayer.mlapi/Tests/Runtime/Profiling/NetworkVariableNameTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e10a16550007020409234a1efb1fa383 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 3abdd50f1eb5944e534f271572f55b1877338078 Mon Sep 17 00:00:00 2001 From: Benoit Doyon Date: Tue, 8 Jun 2021 14:51:14 -0400 Subject: [PATCH 4/9] Code review fixes --- .../Tests/Runtime/Profiling/NetworkVariableNameTests.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/com.unity.multiplayer.mlapi/Tests/Runtime/Profiling/NetworkVariableNameTests.cs b/com.unity.multiplayer.mlapi/Tests/Runtime/Profiling/NetworkVariableNameTests.cs index 2ef7be7994..a85877e65a 100644 --- a/com.unity.multiplayer.mlapi/Tests/Runtime/Profiling/NetworkVariableNameTests.cs +++ b/com.unity.multiplayer.mlapi/Tests/Runtime/Profiling/NetworkVariableNameTests.cs @@ -2,6 +2,7 @@ using MLAPI.NetworkVariable; using MLAPI.NetworkVariable.Collections; using NUnit.Framework; +using UnityEngine; namespace MLAPI.RuntimeTests.Profiling { @@ -46,8 +47,4 @@ private class NetworkVariableNameComponent : NetworkBehaviour public NetworkDictionary NetworkVarDictionary { get; } = new NetworkDictionary(); } } - - public class NetworkMetrics - { - } } \ No newline at end of file From b848fca2ae952136e9180af623de7c02d0768621 Mon Sep 17 00:00:00 2001 From: Benoit Doyon Date: Tue, 8 Jun 2021 14:53:48 -0400 Subject: [PATCH 5/9] Remove rendundant GetType --- com.unity.multiplayer.mlapi/Runtime/Core/NetworkBehaviour.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.multiplayer.mlapi/Runtime/Core/NetworkBehaviour.cs b/com.unity.multiplayer.mlapi/Runtime/Core/NetworkBehaviour.cs index fd75dfb4e9..0c83ecfc84 100644 --- a/com.unity.multiplayer.mlapi/Runtime/Core/NetworkBehaviour.cs +++ b/com.unity.multiplayer.mlapi/Runtime/Core/NetworkBehaviour.cs @@ -445,7 +445,7 @@ internal void InitializeVariables() instance.SetNetworkBehaviour(this); - var instanceNameProperty = instance.GetType().GetProperty(nameof(INetworkVariable.Name)); + var instanceNameProperty = fieldType.GetProperty(nameof(INetworkVariable.Name)); instanceNameProperty?.SetValue(instance, sortedFields[i].Name); NetworkVariableFields.Add(instance); From abbd95c4f4f2d6fa1267fdc46ce62d8460bbc37f Mon Sep 17 00:00:00 2001 From: Benoit Doyon Date: Tue, 8 Jun 2021 15:01:41 -0400 Subject: [PATCH 6/9] Use StringAssert instead of Assert.True --- .../Tests/Runtime/Profiling/NetworkVariableNameTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/com.unity.multiplayer.mlapi/Tests/Runtime/Profiling/NetworkVariableNameTests.cs b/com.unity.multiplayer.mlapi/Tests/Runtime/Profiling/NetworkVariableNameTests.cs index a85877e65a..a09fb9177e 100644 --- a/com.unity.multiplayer.mlapi/Tests/Runtime/Profiling/NetworkVariableNameTests.cs +++ b/com.unity.multiplayer.mlapi/Tests/Runtime/Profiling/NetworkVariableNameTests.cs @@ -30,10 +30,10 @@ public void TearDown() [Test] public void EnsureNetworkVariableNameInitialization() { - Assert.True(m_NetworkVariableNameComponent.NetworkVarString.Name.Contains(nameof(NetworkVariableNameComponent.NetworkVarString))); - Assert.True(m_NetworkVariableNameComponent.NetworkVarSet.Name.Contains(nameof(NetworkVariableNameComponent.NetworkVarSet))); - Assert.True(m_NetworkVariableNameComponent.NetworkVarList.Name.Contains(nameof(NetworkVariableNameComponent.NetworkVarList))); - Assert.True(m_NetworkVariableNameComponent.NetworkVarDictionary.Name.Contains(nameof(NetworkVariableNameComponent.NetworkVarDictionary))); + StringAssert.Contains(nameof(NetworkVariableNameComponent.NetworkVarString), m_NetworkVariableNameComponent.NetworkVarString.Name); + StringAssert.Contains(nameof(NetworkVariableNameComponent.NetworkVarSet), m_NetworkVariableNameComponent.NetworkVarSet.Name); + StringAssert.Contains(nameof(NetworkVariableNameComponent.NetworkVarList), m_NetworkVariableNameComponent.NetworkVarList.Name); + StringAssert.Contains(nameof(NetworkVariableNameComponent.NetworkVarDictionary), m_NetworkVariableNameComponent.NetworkVarDictionary.Name); } private class NetworkVariableNameComponent : NetworkBehaviour From ac5f23c95ce2a8ceba6253d6a5514044a551b8b6 Mon Sep 17 00:00:00 2001 From: Benoit Doyon Date: Tue, 8 Jun 2021 15:37:55 -0400 Subject: [PATCH 7/9] Fix formatting --- .../Tests/Runtime/Profiling/NetworkVariableNameTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com.unity.multiplayer.mlapi/Tests/Runtime/Profiling/NetworkVariableNameTests.cs b/com.unity.multiplayer.mlapi/Tests/Runtime/Profiling/NetworkVariableNameTests.cs index a09fb9177e..f40e31cb2c 100644 --- a/com.unity.multiplayer.mlapi/Tests/Runtime/Profiling/NetworkVariableNameTests.cs +++ b/com.unity.multiplayer.mlapi/Tests/Runtime/Profiling/NetworkVariableNameTests.cs @@ -8,8 +8,8 @@ namespace MLAPI.RuntimeTests.Profiling { public sealed class NetworkVariableNameTests { - NetworkManager m_NetworkManager; - NetworkVariableNameComponent m_NetworkVariableNameComponent; + private NetworkManager m_NetworkManager; + private NetworkVariableNameComponent m_NetworkVariableNameComponent; [SetUp] public void SetUp() From 27aab0e2c0e902e52978c962a2f22e847336e2d2 Mon Sep 17 00:00:00 2001 From: Benoit Doyon Date: Wed, 9 Jun 2021 09:30:26 -0400 Subject: [PATCH 8/9] Remove unused networkmanager reference --- .../Tests/Runtime/Profiling/NetworkVariableNameTests.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/com.unity.multiplayer.mlapi/Tests/Runtime/Profiling/NetworkVariableNameTests.cs b/com.unity.multiplayer.mlapi/Tests/Runtime/Profiling/NetworkVariableNameTests.cs index f40e31cb2c..ea9c74eb20 100644 --- a/com.unity.multiplayer.mlapi/Tests/Runtime/Profiling/NetworkVariableNameTests.cs +++ b/com.unity.multiplayer.mlapi/Tests/Runtime/Profiling/NetworkVariableNameTests.cs @@ -8,13 +8,12 @@ namespace MLAPI.RuntimeTests.Profiling { public sealed class NetworkVariableNameTests { - private NetworkManager m_NetworkManager; private NetworkVariableNameComponent m_NetworkVariableNameComponent; [SetUp] public void SetUp() { - NetworkManagerHelper.StartNetworkManager(out m_NetworkManager); + NetworkManagerHelper.StartNetworkManager(out _); var gameObjectId = NetworkManagerHelper.AddGameNetworkObject(Guid.NewGuid().ToString()); m_NetworkVariableNameComponent= NetworkManagerHelper.AddComponentToObject(gameObjectId); From 29ee2abdb689c50408e770b22e165af2bc1231ef Mon Sep 17 00:00:00 2001 From: Benoit Doyon Date: Wed, 9 Jun 2021 10:23:59 -0400 Subject: [PATCH 9/9] Code review fixes --- .../Runtime/Profiling/NetworkVariableNameTests.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/com.unity.multiplayer.mlapi/Tests/Runtime/Profiling/NetworkVariableNameTests.cs b/com.unity.multiplayer.mlapi/Tests/Runtime/Profiling/NetworkVariableNameTests.cs index ea9c74eb20..46f3f1130c 100644 --- a/com.unity.multiplayer.mlapi/Tests/Runtime/Profiling/NetworkVariableNameTests.cs +++ b/com.unity.multiplayer.mlapi/Tests/Runtime/Profiling/NetworkVariableNameTests.cs @@ -27,12 +27,15 @@ public void TearDown() } [Test] - public void EnsureNetworkVariableNameInitialization() + public void VerifyNetworkVariableNameInitialization() { + // Properties have the following name format: "k__BackingField" StringAssert.Contains(nameof(NetworkVariableNameComponent.NetworkVarString), m_NetworkVariableNameComponent.NetworkVarString.Name); StringAssert.Contains(nameof(NetworkVariableNameComponent.NetworkVarSet), m_NetworkVariableNameComponent.NetworkVarSet.Name); - StringAssert.Contains(nameof(NetworkVariableNameComponent.NetworkVarList), m_NetworkVariableNameComponent.NetworkVarList.Name); - StringAssert.Contains(nameof(NetworkVariableNameComponent.NetworkVarDictionary), m_NetworkVariableNameComponent.NetworkVarDictionary.Name); + + // Fields have regular naming + Assert.AreEqual(nameof(NetworkVariableNameComponent.NetworkVarList), m_NetworkVariableNameComponent.NetworkVarList.Name); + Assert.AreEqual(nameof(NetworkVariableNameComponent.NetworkVarDictionary), m_NetworkVariableNameComponent.NetworkVarDictionary.Name); } private class NetworkVariableNameComponent : NetworkBehaviour @@ -41,9 +44,9 @@ private class NetworkVariableNameComponent : NetworkBehaviour public NetworkSet NetworkVarSet { get; } = new NetworkSet(); - public NetworkList NetworkVarList { get; } = new NetworkList(); + public NetworkList NetworkVarList = new NetworkList(); - public NetworkDictionary NetworkVarDictionary { get; } = new NetworkDictionary(); + public NetworkDictionary NetworkVarDictionary = new NetworkDictionary(); } } } \ No newline at end of file