// ----------------------------------------------------------------------------------- // // ----------------------------------------------------------------------------------- public void OnClientSwitchServerRequested(NetworkConnection connection, SwitchServerMsg message) { print("OnClientSwitchServerRequested: " + message.scenePath); // only on client if (!NetworkServer.active) { UCE_UI_Tools.FadeOutScreen(false); print("[Zones]: disconnecting from current server"); manager.StopClient(); NetworkClient.Shutdown(); NetworkManager.Shutdown(); // clears singleton too NetworkManager.singleton = manager; // setup singleton again print("[Zones]: loading required scene: " + message.scenePath); autoSelectCharacter = message.characterName; string sceneName = Path.GetFileNameWithoutExtension(message.scenePath); SceneManager.LoadScene(sceneName); autoConnectClient = true; } }
public void OnClientSwitchServerRequested(NetworkConnection conn, SwitchServerMsg message) { // We only want to do this on the client, skip if the server is active if (NetworkServer.active) { return; } var sceneName = Path.GetFileNameWithoutExtension(message.scenePath); // TODO: add validation for message contents print("[Zones]: OnClientSwitchServerRequested: " + sceneName); print("[Zones]: disconnecting from current server"); manager.StopClient(); // clean up as much as possible. // if we don't call NetworkManager.Shutdown then objects aren't // spawned on the client anymore after connecting to scene #2 for // the second time. NetworkClient.Shutdown(); NetworkManager.Shutdown(); // clears singleton too NetworkManager.singleton = manager; // setup singleton again Transport.activeTransport.enabled = false; // don't receive while switching scenes print("[Zones]: loading required scene: " + sceneName); autoSelectCharacter = message.characterName; // load requested scene and make sure to auto connect when it's done // TODO: Change to Async with loading screen SceneManager.LoadScene(sceneName); autoConnectClient = true; }