Ejemplo n.º 1
0
        // This delay is mostly for the host player that loads too fast for the
        // server to have subscenes async loaded from OnStartServer ahead of it.
        IEnumerator OnServerAddPlayerDelayed(NetworkConnection conn)
        {
            // wait for server to async load all subscenes for game instances
            while (!subscenesLoaded)
            {
                yield return(null);
            }

            conn.Send(new SceneMessage {
                sceneName = gameScene, sceneOperation = SceneOperation.LoadAdditive
            });

            base.OnServerAddPlayer(conn);

            PlayerScore playerScore = conn.identity.GetComponent <PlayerScore>();

            playerScore.playerNumber = clientIndex;
            playerScore.scoreIndex   = clientIndex / subScenes.Count;
            playerScore.matchIndex   = clientIndex % subScenes.Count;

            clientIndex++;

            if (subScenes.Count > 0)
            {
                SceneManager.MoveGameObjectToScene(conn.identity.gameObject, subScenes[clientIndex % subScenes.Count]);
            }
        }
Ejemplo n.º 2
0
        // This delay is mostly for the host player that loads too fast for the
        // server to have subscenes async loaded from OnStartServer ahead of it.
        IEnumerator OnServerAddPlayerDelayed(NetworkConnectionToClient conn)
        {
            // wait for server to async load all subscenes for game instances
            while (!subscenesLoaded)
            {
                yield return(null);
            }

            // Send Scene message to client to additively load the game scene
            conn.Send(new SceneMessage {
                sceneName = gameScene, sceneOperation = SceneOperation.LoadAdditive
            });

            // Wait for end of frame before adding the player to ensure Scene Message goes first
            yield return(new WaitForEndOfFrame());

            base.OnServerAddPlayer(conn);

            PlayerScore playerScore = conn.identity.GetComponent <PlayerScore>();

            playerScore.playerNumber = clientIndex;
            playerScore.scoreIndex   = clientIndex / subScenes.Count;
            playerScore.matchIndex   = clientIndex % subScenes.Count;

            // Do this only on server, not on clients
            // This is what allows the NetworkSceneChecker on player and scene objects
            // to isolate matches per scene instance on server.
            if (subScenes.Count > 0)
            {
                SceneManager.MoveGameObjectToScene(conn.identity.gameObject, subScenes[clientIndex % subScenes.Count]);
            }

            clientIndex++;
        }
        IEnumerator AddPlayerDelayed(NetworkConnection conn)
        {
            yield return(new WaitForSeconds(.5f));

            conn.Send(new SceneMessage {
                sceneName = gameScene, sceneOperation = SceneOperation.LoadAdditive
            });

            base.OnServerAddPlayer(conn);

            PlayerScore playerScore = conn.identity.GetComponent <PlayerScore>();

            playerScore.playerNumber = conn.connectionId;
            playerScore.scoreIndex   = conn.connectionId / subScenes.Count;
            playerScore.matchIndex   = conn.connectionId % subScenes.Count;

            if (subScenes.Count > 0)
            {
                SceneManager.MoveGameObjectToScene(conn.identity.gameObject, subScenes[conn.connectionId % subScenes.Count]);
            }
        }