/// <summary> /// Register network players so we have all of them /// </summary> public void RegisterMPNetworkPlayer(MPNetworkPlayer newPlayer) { Debug.Log("Player joined"); connectedPlayers.Add(newPlayer); newPlayer.BecameReady += OnPlayerSetReady; // Send initial scene message string sceneName = SceneManager.GetActiveScene().name; if (sceneName == GameSceneName) { newPlayer.OnEnterGameScene(); } else if (sceneName == MainMenuSceneName) { newPlayer.OnEnterLobbyScene(); } if (playerJoined != null) { playerJoined(newPlayer); } newPlayer.GameDetailsReady += FireGameModeUpdated; }
public override void OnClientSceneChanged(NetworkConnection conn) { Debug.Log("OnClientSceneChanged"); base.OnClientSceneChanged(conn); PlayerController pc = conn.playerControllers[0]; if (!pc.unetView.isLocalPlayer) { return; } string sceneName = SceneManager.GetActiveScene().name; if (sceneName == GameSceneName) { state = NetworkState.InGame; // Tell all network players that they're in the game scene for (int i = 0; i < connectedPlayers.Count; ++i) { MPNetworkPlayer np = connectedPlayers[i]; if (np != null) { np.OnEnterGameScene(); } } } else if (sceneName == MainMenuSceneName) { if (state != NetworkState.Inactive) { if (gameType == NetworkGameType.SinglePlayer) { state = NetworkState.Pregame; } else { state = NetworkState.InLobby; } } // Tell all network players that they're in the lobby scene for (int i = 0; i < connectedPlayers.Count; ++i) { MPNetworkPlayer np = connectedPlayers[i]; if (np != null) { np.OnEnterLobbyScene(); } } } if (sceneChanged != null) { sceneChanged(false, sceneName); } }