Ejemplo n.º 1
0
        /// <summary>
        /// Register network players so we have all of them
        /// </summary>
        public void RegisterNetworkPlayer(NetworkPlayer newPlayer)
        {
            Debug.Log("Player joined");

            connectedPlayers.Add(newPlayer);
            newPlayer.becameReady += OnPlayerSetReady;

            if (s_IsServer)
            {
                UpdatePlayerIDs();
            }

            // Send initial scene message
            string sceneName = SceneManager.GetActiveScene().name;

            if (sceneName == s_LobbySceneName)
            {
                newPlayer.OnEnterLobbyScene();
            }

            if (playerJoined != null)
            {
                playerJoined(newPlayer);
            }

            newPlayer.gameDetailsReady += FireGameModeUpdated;
        }
Ejemplo n.º 2
0
        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 == 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);
            }
        }