public override void OnClientSceneChanged(NetworkConnection conn) { MapDetails currentMap = m_Settings.map; Debug.Log("OnClientSceneChanged"); base.OnClientSceneChanged(conn); PlayerController pc = conn.playerControllers[0]; if (!pc.unetView.isLocalPlayer) { return; } string sceneName = SceneManager.GetActiveScene().name; if (currentMap != null && sceneName == currentMap.sceneName) { state = NetworkState.InGame; // Tell all network players that they're in the game scene for (int i = 0; i < connectedPlayers.Count; ++i) { NetworkPlayer np = connectedPlayers[i]; if (np != null) { np.OnEnterGameScene(); } } } else if (sceneName == s_LobbySceneName) { 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) { NetworkPlayer np = connectedPlayers[i]; if (np != null) { np.OnEnterLobbyScene(); } } } if (sceneChanged != null) { sceneChanged(false, sceneName); } }
/// <summary> /// Register network players so we have all of them /// </summary> public void RegisterNetworkPlayer(NetworkPlayer newPlayer) { MapDetails currentMap = m_Settings.map; connectedPlayers.Add(newPlayer); newPlayer.becameReady += OnPlayerSetReady; if (s_IsServer) { UpdatePlayerIDs(); } // Send initial scene message string sceneName = SceneManager.GetActiveScene().name; if (currentMap != null && sceneName == currentMap.sceneName) { newPlayer.OnEnterGameScene(); } else if (sceneName == s_LobbySceneName) { newPlayer.OnEnterLobbyScene(); } if (playerJoined != null) { playerJoined(newPlayer); } // AgoraPlayerController.instance.AddNetworkPlayer(newPlayer); newPlayer.gameDetailsReady += FireGameModeUpdated; }
/// -------------------------------------------------------------------------------------------------------- /// <summary> /// 增加一个玩家到本地游戏中 /// </summary> /// -------------------------------------------------------------------------------------------------------- public void RegisterNetworkPlayer(NetworkPlayer newPlayer) { MapDetails currentMap = m_Settings.map; Debug.Log("Player joined"); connectedPlayers.Add(newPlayer); playerList.Add(newPlayer.gameObject); newPlayer.becameReady += OnPlayerSetReady; if (s_IsServer) { UpdatePlayerIDs(); } string sceneName = SceneManager.GetActiveScene().name; if (currentMap != null && sceneName == currentMap.sceneName) { newPlayer.OnEnterGameScene(); } else if (sceneName == s_LobbySceneName) { newPlayer.OnEnterLobbyScene(); } if (playerJoined != null) { playerJoined(newPlayer); } newPlayer.gameDetailsReady += FireGameModeUpdated; }