diff --git a/Assets/Mirror/Tests/Editor/NetworkBehaviourTests.cs b/Assets/Mirror/Tests/Editor/NetworkBehaviourTests.cs index 329b96106..84dd3e6a0 100644 --- a/Assets/Mirror/Tests/Editor/NetworkBehaviourTests.cs +++ b/Assets/Mirror/Tests/Editor/NetworkBehaviourTests.cs @@ -115,6 +115,21 @@ public void SetSyncVarGameObjectExposed(GameObject newGameObject, ulong dirtyBit } } + // we need to inherit from networkbehaviour to test protected functions + public class NetworkBehaviourGetSyncVarGameObjectComponent : NetworkBehaviour + { + //[SyncVar] + public GameObject test; + // usually generated by weaver + public uint testNetId; + + // SetSyncVarGameObject wrapper to expose it + public GameObject GetSyncVarGameObjectExposed() + { + return GetSyncVarGameObject(testNetId, ref test); + } + } + public class NetworkBehaviourTests { GameObject gameObject; @@ -1029,6 +1044,39 @@ public void SetSyncVarGameObjectZeroNetId() GameObject.DestroyImmediate(test); GameObject.DestroyImmediate(go); } + + [Test] + public void GetSyncVarGameObjectOnServer() + { + // isServer is only true if we have a server running and netId set + Transport.activeTransport = Substitute.For(); + NetworkServer.Listen(1); + identity.netId = 42; // otherwise isServer is false + Assert.That(identity.isServer, Is.True); + + // add test component + NetworkBehaviourGetSyncVarGameObjectComponent comp = gameObject.AddComponent(); + comp.syncInterval = 0; // for isDirty check + + // create a syncable GameObject + GameObject go = new GameObject(); + NetworkIdentity ni = go.AddComponent(); + ni.netId = 43; + + // assign it in the component + comp.test = go; + comp.testNetId = ni.netId; + + // get it on the server. should simply return the field instead of + // doing any netId lookup like on the client + GameObject result = comp.GetSyncVarGameObjectExposed(); + Assert.That(result, Is.EqualTo(go)); + + // clean up + NetworkServer.Shutdown(); + Transport.activeTransport = null; + GameObject.DestroyImmediate(go); + } } // we need to inherit from networkbehaviour to test protected functions