remove unnecessary HostMode.ActivateHostScene function.

this would call OnStartClient for scene objects if .isClient was false.
however, NetworkManager.FinishStartHost calls NetworkServer.SpawnObjects first.
which always sets isClient = true for all scene objects.
This commit is contained in:
vis2k 2023-01-28 12:46:12 +09:00
parent bb6c0de495
commit b6cee2aae2
3 changed files with 5 additions and 37 deletions

View File

@ -1,6 +1,8 @@
// host mode related helper functions.
// usually they set up both server & client.
// it's cleaner to keep them in one place, instead of only in server / client.
using System;
namespace Mirror
{
public static class HostMode
@ -39,19 +41,8 @@ public static void InvokeOnConnected()
((LocalConnectionToServer)NetworkClient.connection).QueueConnectedEvent();
}
// calls OnStartClient for all SERVER objects in host mode once.
// client doesn't get spawn messages for those, so need to call manually.
// public because NetworkServer.ActivateHostScene was public before too.
public static void ActivateHostScene()
{
foreach (NetworkIdentity identity in NetworkServer.spawned.Values)
{
if (!identity.isClient)
{
// Debug.Log($"ActivateHostScene {identity.netId} {identity}");
NetworkClient.CheckForStartClient(identity);
}
}
}
// DEPRECATED 2023-01-28
[Obsolete("ActivateHostScene did nothing, since identities all had .isClient set in NetworkServer.SpawnObjects.")]
public static void ActivateHostScene() {}
}
}

View File

@ -523,7 +523,6 @@ void FinishStartHost()
SetupClient();
networkAddress = "localhost";
HostMode.ActivateHostScene();
RegisterClientMessages();
// call OnConencted needs to be called AFTER RegisterClientMessages

View File

@ -839,28 +839,6 @@ public void SendCommand_RequiresAuthority()
Assert.That(comp.called, Is.EqualTo(0));
}
[Test]
public void ActivateHostSceneCallsOnStartClient()
{
// listen & connect
NetworkServer.Listen(1);
ConnectClientBlockingAuthenticatedAndReady(out _);
// spawn identity with a networkbehaviour.
// (needs to be in .spawned for ActivateHostScene)
CreateNetworkedAndSpawn(
out _, out NetworkIdentity serverIdentity, out OnStartClientTestNetworkBehaviour serverComp,
out _, out _, out _);
// ActivateHostScene calls OnStartClient for spawned objects where
// isClient is still false. set it to false first.
serverIdentity.isClient = false;
HostMode.ActivateHostScene();
// was OnStartClient called for all .spawned networkidentities?
Assert.That(serverComp.called, Is.EqualTo(1));
}
[Test]
public void SendToAll()
{