diff --git a/Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs b/Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs index a3f4a4035..a1616a838 100644 --- a/Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs +++ b/Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs @@ -223,6 +223,14 @@ public override bool OnRebuildObservers(HashSet observers, bo // OnRebuildObservers, but return no observers return true; } + + public int hostVisibilityCalled; + public bool hostVisibilityValue; + public override void OnSetHostVisibility(bool visible) + { + ++hostVisibilityCalled; + hostVisibilityValue = visible; + } } class IsClientServerCheckComponent : NetworkBehaviour @@ -1443,5 +1451,34 @@ public void RebuildObserversDoesNotAddServerConnectionsIfImplemented() NetworkServer.Shutdown(); Transport.activeTransport = null; } + + [Test] + public void RebuildObserversSetsHostVisibility() + { + // set local connection for host mode + ULocalConnectionToClient localConnection = new ULocalConnectionToClient(); + localConnection.connectionToServer = new ULocalConnectionToServer(); + localConnection.isReady = true; + NetworkServer.SetLocalConnection(localConnection); + + // add at least one observers component, otherwise it will just add + // all server connections + RebuildEmptyObserversNetworkBehaviour comp = gameObject.AddComponent(); + Assert.That(comp.hostVisibilityCalled, Is.EqualTo(0)); + + // call OnStartServer so that observers dict is created + identity.OnStartServer(); + + // rebuild will result in 0 observers. it won't contain host + // connection so it should call OnSetHostVisibility(false) + identity.RebuildObservers(true); + Assert.That(identity.observers.Count, Is.EqualTo(0)); + Assert.That(comp.hostVisibilityCalled, Is.EqualTo(1)); + Assert.That(comp.hostVisibilityValue, Is.False); + + // clean up + NetworkServer.RemoveLocalConnection(); + NetworkServer.Shutdown(); + } } }