public void ActivateHostSceneCallsOnStartClient() { // add an identity with a networkbehaviour to .spawned GameObject go = new GameObject(); NetworkIdentity identity = go.AddComponent <NetworkIdentity>(); identity.netId = 42; // for authority check //identity.connectionToClient = connection; OnStartClientTestNetworkBehaviour comp = go.AddComponent <OnStartClientTestNetworkBehaviour>(); Assert.That(comp.called, Is.EqualTo(0)); //connection.identity = identity; NetworkIdentity.spawned[identity.netId] = identity; // ActivateHostScene NetworkServer.ActivateHostScene(); // was OnStartClient called for all .spawned networkidentities? Assert.That(comp.called, Is.EqualTo(1)); // clean up NetworkIdentity.spawned.Clear(); NetworkServer.Shutdown(); // destroy the test gameobject AFTER server was stopped. // otherwise isServer is true in OnDestroy, which means it would try // to call Destroy(go). but we need to use DestroyImmediate in // Editor GameObject.DestroyImmediate(go); }
public void Setup() { // start server/client NetworkServer.Listen(1); NetworkClient.ConnectHost(); NetworkServer.SpawnObjects(); NetworkServer.ActivateHostScene(); NetworkClient.ConnectLocalServer(); NetworkServer.localConnection.isAuthenticated = true; NetworkClient.connection.isAuthenticated = true; NetworkClient.Ready(); }
public void ActivateHostSceneCallsOnStartClient() { // add an identity with a networkbehaviour to .spawned CreateNetworked(out GameObject _, out NetworkIdentity identity, out OnStartClientTestNetworkBehaviour comp); identity.netId = 42; NetworkIdentity.spawned[identity.netId] = identity; // ActivateHostScene NetworkServer.ActivateHostScene(); // was OnStartClient called for all .spawned networkidentities? Assert.That(comp.called, Is.EqualTo(1)); }
public void Setup() { Transport.activeTransport = new GameObject().AddComponent <MemoryTransport>(); // start server/client NetworkServer.Listen(1); NetworkClient.ConnectHost(); NetworkServer.SpawnObjects(); NetworkServer.ActivateHostScene(); NetworkClient.ConnectLocalServer(); NetworkServer.localConnection.isAuthenticated = true; NetworkClient.connection.isAuthenticated = true; ClientScene.Ready(NetworkClient.connection); }
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; NetworkServer.ActivateHostScene(); // was OnStartClient called for all .spawned networkidentities? Assert.That(serverComp.called, Is.EqualTo(1)); }