Class NetworkSceneManager
NetworkSceneManager is an optional component that helps keep scene in sync between server and client. The loads scenes as instructed by the . The controls the currently active Scene and any additive Load/Unload. when a client connect NetworkSceneManager will send a message telling the new client to load the scene that is active on the server
Inheritance
Syntax
public class NetworkSceneManager : MonoBehaviour
Fields
Client
Declaration
public NetworkClient Client
Server
Declaration
public NetworkServer Server
ServerObjectManager
Declaration
public ServerObjectManager ServerObjectManager
ClientObjectManager
Declaration
public ClientObjectManager ClientObjectManager
SendAdditiveScenesOnAuthenticate
Declaration
public bool SendAdditiveScenesOnAuthenticate
DontDestroy
Sets the NetworksSceneManagers GameObject to DontDestroyOnLoad. Default = true.
Declaration
public bool DontDestroy
SceneLoadingAsyncOperationInfo
Information on any scene that is currently being loaded.
Declaration
public AsyncOperation SceneLoadingAsyncOperationInfo
Properties
ActiveScenePath
The path of the current active scene. If using additive scenes this will be the first scene. Value from
Declaration
public string ActiveScenePath { get; }
ServerSceneData
Collection of scenes and which player's are in those scenes.
Declaration
public IReadOnlyDictionary<Scene, HashSet<INetworkPlayer>> ServerSceneData { get; }
OnClientStartedSceneChange
Event fires when the Client starts changing scene.
Declaration
public SceneChangeStartedEvent OnClientStartedSceneChange { get; }
OnClientFinishedSceneChange
Event fires after the Client has completed its scene change.
Declaration
public SceneChangeFinishedEvent OnClientFinishedSceneChange { get; }
OnServerStartedSceneChange
Event fires before Server changes scene.
Declaration
public SceneChangeStartedEvent OnServerStartedSceneChange { get; }
OnServerFinishedSceneChange
Event fires after Server has completed scene change.
Declaration
public SceneChangeFinishedEvent OnServerFinishedSceneChange { get; }
OnPlayerSceneReady
Event fires On the server, after Client sends to the server
Declaration
public PlayerSceneChangeEvent OnPlayerSceneReady { get; }
Methods
Start()
Declaration
public virtual void Start()
OnDestroy()
Declaration
public virtual void OnDestroy()
IsPlayerInScene(Scene, INetworkPlayer)
Check whether or not the player is in a specific scene or not.
Declaration
public bool IsPlayerInScene(Scene scene, INetworkPlayer player)
Parameters
Type | Name | Description |
---|---|---|
Scene | scene | The scene we want to check in. |
Mirage.INetworkPlayer | player | The player we want to check for. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true or false if the player is in the scene specified. |
ScenesPlayerIsIn(INetworkPlayer)
What scene is this specific player currently in.
Declaration
public Scene[] ScenesPlayerIsIn(INetworkPlayer player)
Parameters
Type | Name | Description |
---|---|---|
Mirage.INetworkPlayer | player | The player we want to check against. |
Returns
Type | Description |
---|---|
Scene[] | Returns back a array of scene's the player is currently in. |
ScenesPlayerIsInNonAlloc(INetworkPlayer, List<Scene>)
Declaration
public void ScenesPlayerIsInNonAlloc(INetworkPlayer player, List<Scene> scenes)
Parameters
Type | Name | Description |
---|---|---|
Mirage.INetworkPlayer | player | |
System.Collections.Generic.List<Scene> | scenes |
ClientStartSceneMessage(INetworkPlayer, SceneMessage)
Received message from server to start loading scene or scenes.
Default implementation is to load main activate scene server is using and load any other additive scenes in background and notify event handler. If this is not intended behavior you need please override this function.
Declaration
public virtual void ClientStartSceneMessage(INetworkPlayer player, SceneMessage message)
Parameters
Type | Name | Description |
---|---|---|
Mirage.INetworkPlayer | player | |
Mirage.SceneMessage | message |
ClientFinishedLoadingSceneMessage(INetworkPlayer, SceneReadyMessage)
Received message from server that it has finished loading the scene.
Default implementation will set AllowSceneActivation = true and invoke event handler. If this is not good enough intended behavior then override this method.
Declaration
protected virtual void ClientFinishedLoadingSceneMessage(INetworkPlayer player, SceneReadyMessage message)
Parameters
Type | Name | Description |
---|---|---|
Mirage.INetworkPlayer | player | The player who sent the message. |
Mirage.SceneReadyMessage | message | The message data coming back from server. |
ClientNotReadyMessage(INetworkPlayer, SceneNotReadyMessage)
Received message that player is not ready.
Default implementation is to set player to not ready.
Declaration
protected virtual void ClientNotReadyMessage(INetworkPlayer player, SceneNotReadyMessage message)
Parameters
Type | Name | Description |
---|---|---|
Mirage.INetworkPlayer | player | The player that is currently not ready. |
Mirage.SceneNotReadyMessage | message | The message data coming in. |
SetSceneIsReady()
Signal that the client connection is ready to enter the game. This could be for example when a client enters an ongoing game and has finished loading the current scene. The server should respond to the message with an appropriate handler which instantiates the players object for example.
Declaration
public void SetSceneIsReady()
ServerLoadForPlayers(String, IEnumerable<INetworkPlayer>, Boolean, SceneOperation)
Loads a scene on players but NOT on server Note: does not load for Host player, they should be loaded using server methods instead
Declaration
public void ServerLoadForPlayers(string scenePath, IEnumerable<INetworkPlayer> players, bool shouldClientLoadOrUnloadNormally, SceneOperation sceneOperation = SceneOperation.Normal)
Parameters
Type | Name | Description |
---|---|---|
System.String | scenePath | |
System.Collections.Generic.IEnumerable<Mirage.INetworkPlayer> | players | |
System.Boolean | shouldClientLoadOrUnloadNormally | |
Mirage.SceneOperation | sceneOperation |
ServerSceneUnLoading(Scene, IEnumerable<INetworkPlayer>)
Unload a specific scene from server and clients
Declaration
public void ServerSceneUnLoading(Scene scene, IEnumerable<INetworkPlayer> players)
Parameters
Type | Name | Description |
---|---|---|
Scene | scene | What scene do we want to tell server and clients to unload. |
System.Collections.Generic.IEnumerable<Mirage.INetworkPlayer> | players | The players we want to tell to unload the scene. |
ServerSceneUnLoadingAsync(Scene, IEnumerable<INetworkPlayer>)
Unload a specific scene from server and clients
Declaration
public UniTask ServerSceneUnLoadingAsync(Scene scene, IEnumerable<INetworkPlayer> players)
Parameters
Type | Name | Description |
---|---|---|
Scene | scene | What scene do we want to tell server and clients to unload. |
System.Collections.Generic.IEnumerable<Mirage.INetworkPlayer> | players | The players we want to tell to unload the scene. |
Returns
Type | Description |
---|---|
Cysharp.Threading.Tasks.UniTask |
ServerLoadSceneNormal(String, Nullable<LoadSceneParameters>)
Allows server to fully load in a new scene and override current active scene.
Declaration
public void ServerLoadSceneNormal(string scenePath, LoadSceneParameters? sceneLoadParameters = default(LoadSceneParameters? ))
Parameters
Type | Name | Description |
---|---|---|
System.String | scenePath | The full path to the scene file or the name of the scene. |
System.Nullable<LoadSceneParameters> | sceneLoadParameters | What settings should we be using for physics scene loading. |
ServerLoadSceneNormalAsync(String, Nullable<LoadSceneParameters>)
Allows server to fully load in a new scene and override current active scene.
Declaration
public UniTask ServerLoadSceneNormalAsync(string scenePath, LoadSceneParameters? sceneLoadParameters = default(LoadSceneParameters? ))
Parameters
Type | Name | Description |
---|---|---|
System.String | scenePath | The full path to the scene file or the name of the scene. |
System.Nullable<LoadSceneParameters> | sceneLoadParameters | What settings should we be using for physics scene loading. |
Returns
Type | Description |
---|---|
Cysharp.Threading.Tasks.UniTask |
ServerLoadSceneAdditively(String, IEnumerable<INetworkPlayer>, Boolean, Nullable<LoadSceneParameters>)
Allows server to fully load in another scene on top of current active scene.
Declaration
public void ServerLoadSceneAdditively(string scenePath, IEnumerable<INetworkPlayer> players, bool shouldClientLoadNormally = false, LoadSceneParameters? sceneLoadParameters = default(LoadSceneParameters? ))
Parameters
Type | Name | Description |
---|---|---|
System.String | scenePath | The full path to the scene file or the name of the scene. |
System.Collections.Generic.IEnumerable<Mirage.INetworkPlayer> | players | Collection of player's that are receiving the new scene load. |
System.Boolean | shouldClientLoadNormally | Should the clients load this additively too or load it full normal scene change. |
System.Nullable<LoadSceneParameters> | sceneLoadParameters | What settings should we be using for physics scene loading. |
ServerLoadSceneAdditivelyAsync(String, IEnumerable<INetworkPlayer>, Boolean, Nullable<LoadSceneParameters>)
Allows server to fully load in another scene on top of current active scene.
Declaration
public UniTask ServerLoadSceneAdditivelyAsync(string scenePath, IEnumerable<INetworkPlayer> players, bool shouldClientLoadNormally = false, LoadSceneParameters? sceneLoadParameters = default(LoadSceneParameters? ))
Parameters
Type | Name | Description |
---|---|---|
System.String | scenePath | The full path to the scene file or the name of the scene. |
System.Collections.Generic.IEnumerable<Mirage.INetworkPlayer> | players | Collection of player's that are receiving the new scene load. |
System.Boolean | shouldClientLoadNormally | Should the clients load this additively too or load it full normal scene change. |
System.Nullable<LoadSceneParameters> | sceneLoadParameters | What settings should we be using for physics scene loading. |
Returns
Type | Description |
---|---|
Cysharp.Threading.Tasks.UniTask |
ServerUnloadSceneAdditively(Scene, IEnumerable<INetworkPlayer>)
Allows server to fully unload a scene additively.
Declaration
public void ServerUnloadSceneAdditively(Scene scene, IEnumerable<INetworkPlayer> players)
Parameters
Type | Name | Description |
---|---|---|
Scene | scene | The scene handle which we want to unload additively. |
System.Collections.Generic.IEnumerable<Mirage.INetworkPlayer> | players | Collection of player's that are receiving the new scene unload. |
ServerUnloadSceneAdditivelyAsync(Scene, IEnumerable<INetworkPlayer>)
Allows server to fully unload a scene additively.
Declaration
public UniTask ServerUnloadSceneAdditivelyAsync(Scene scene, IEnumerable<INetworkPlayer> players)
Parameters
Type | Name | Description |
---|---|---|
Scene | scene | The scene handle which we want to unload additively. |
System.Collections.Generic.IEnumerable<Mirage.INetworkPlayer> | players | Collection of player's that are receiving the new scene unload. |
Returns
Type | Description |
---|---|
Cysharp.Threading.Tasks.UniTask |
OnServerAuthenticated(INetworkPlayer)
When player authenticates to server we send a message to them to load up main scene and any other scenes that are loaded on server.
Default implementation takes main activate scene as main and any other loaded scenes and sends it to player's Please override this function if this is not intended behavior for you.
Declaration
protected virtual void OnServerAuthenticated(INetworkPlayer player)
Parameters
Type | Name | Description |
---|---|---|
Mirage.INetworkPlayer | player | The current player that finished authenticating. |
OnServerPlayerDisconnected(INetworkPlayer)
When player disconnects from server we will need to clean up info in scenes related to user. Default implementation we loop through list of scenes and find where this player was in and removed them from list.
Declaration
protected virtual void OnServerPlayerDisconnected(INetworkPlayer disconnectedPlayer)
Parameters
Type | Name | Description |
---|---|---|
Mirage.INetworkPlayer | disconnectedPlayer |
SetAllClientsNotReady(IEnumerable<INetworkPlayer>)
Marks all connected clients as no longer ready.
All clients will no longer be sent state synchronization updates.
The player's clients can call ClientManager.Ready() again to re-enter the ready state.
This is useful when switching scenes.
Declaration
public void SetAllClientsNotReady(IEnumerable<INetworkPlayer> players = null)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<Mirage.INetworkPlayer> | players |
SetClientNotReady(INetworkPlayer)
Sets a player as not ready and removes all visible objects Players that are not ready will not be sent spawn message or state updates. Players that are not ready do not receive spawned objects or state synchronization updates. They client can be made ready again by calling SetClientReady().
Declaration
public void SetClientNotReady(INetworkPlayer player)
Parameters
Type | Name | Description |
---|---|---|
Mirage.INetworkPlayer | player | The player to make not ready. |
GetSceneByPathOrName(String)
Let's us get scene by full path or by its name.
Declaration
public Scene GetSceneByPathOrName(string scenePath)
Parameters
Type | Name | Description |
---|---|---|
System.String | scenePath | The path or name representing the scene. |
Returns
Type | Description |
---|---|
Scene | Returns back correct scene data. |