Class SceneManager
Handles loading, unloading, and scene visibility for clients.
Inheritance
Inherited Members
Namespace: FishNet.Managing.Scened
Assembly: FishNet.Runtime.dll
Syntax
[DisallowMultipleComponent]
[AddComponentMenu("FishNet/Manager/SceneManager")]
public sealed class SceneManager : MonoBehaviour
Properties
NetworkManager
NetworkManager for this script.
Declaration
public NetworkManager NetworkManager { get; }
Property Value
| Type | Description |
|---|---|
| NetworkManager |
SceneConnections
Connections within each scene.
Declaration
public Dictionary<Scene, HashSet<NetworkConnection>> SceneConnections { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.Dictionary<UnityEngine.SceneManagement.Scene, System.Collections.Generic.HashSet<NetworkConnection>> |
Methods
AddConnectionToScene(NetworkConnection, Scene)
Adds a connection to a scene. This will always be called one connection at a time because connections are only added after they invidually validate loading the scene. Exposed for power users, use caution.
Declaration
public void AddConnectionToScene(NetworkConnection conn, Scene scene)
Parameters
| Type | Name | Description |
|---|---|---|
| NetworkConnection | conn | Connection to add. |
| UnityEngine.SceneManagement.Scene | scene | Scene to add the connection to. |
AddOwnerToDefaultScene(NetworkObject)
Adds the owner of nob to the gameObjects scene if there are no global scenes.
Declaration
public void AddOwnerToDefaultScene(NetworkObject nob)
Parameters
| Type | Name | Description |
|---|---|---|
| NetworkObject | nob |
GetScene(Int32)
Returns a scene by handle.
Declaration
public static Scene GetScene(int sceneHandle)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | sceneHandle |
Returns
| Type | Description |
|---|---|
| UnityEngine.SceneManagement.Scene |
GetScene(String, NetworkManager, Boolean)
Returns a scene by name.
Declaration
public static Scene GetScene(string sceneName, NetworkManager nm = null, bool warnIfDuplicates = true)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | sceneName | Name of scene to retrieve. |
| NetworkManager | nm | NetworkManager to use for debug print. This value may be left null. |
| System.Boolean | warnIfDuplicates | True to warn if scene name is found loaded multiple times. |
Returns
| Type | Description |
|---|---|
| UnityEngine.SceneManagement.Scene |
GetSceneProcessor()
Script to handle addressables loading and unloading. This field may be blank if addressables are not being used.
Declaration
public SceneProcessorBase GetSceneProcessor()
Returns
| Type | Description |
|---|---|
| SceneProcessorBase |
LoadConnectionScenes(NetworkConnection, SceneLoadData)
Loads scenes on server and tells connections to load them as well. Other connections will not load this scene.
Declaration
public void LoadConnectionScenes(NetworkConnection conn, SceneLoadData sceneLoadData)
Parameters
| Type | Name | Description |
|---|---|---|
| NetworkConnection | conn | Connections to load scenes for. |
| SceneLoadData | sceneLoadData | Data about which scenes to load. |
LoadConnectionScenes(NetworkConnection[], SceneLoadData)
Loads scenes on server and tells connections to load them as well. Other connections will not load this scene.
Declaration
public void LoadConnectionScenes(NetworkConnection[] conns, SceneLoadData sceneLoadData)
Parameters
| Type | Name | Description |
|---|---|---|
| NetworkConnection[] | conns | Connections to load scenes for. |
| SceneLoadData | sceneLoadData | Data about which scenes to load. |
LoadConnectionScenes(SceneLoadData)
Loads scenes on server without telling clients to load the scenes.
Declaration
public void LoadConnectionScenes(SceneLoadData sceneLoadData)
Parameters
| Type | Name | Description |
|---|---|---|
| SceneLoadData | sceneLoadData | Data about which scenes to load. |
LoadGlobalScenes(SceneLoadData)
Loads scenes on the server and for all clients. Future clients will automatically load these scenes.
Declaration
public void LoadGlobalScenes(SceneLoadData sceneLoadData)
Parameters
| Type | Name | Description |
|---|---|---|
| SceneLoadData | sceneLoadData | Data about which scenes to load. |
RemoveAllConnectionsFromScene(Scene)
Removes all connections from a scene.
Declaration
public void RemoveAllConnectionsFromScene(Scene scene)
Parameters
| Type | Name | Description |
|---|---|---|
| UnityEngine.SceneManagement.Scene | scene | Scene to remove connections from. |
RemoveConnectionsFromNonGlobalScenes(NetworkConnection[])
Removes connections from any scene which is not global. Exposed for power users, use caution.
Declaration
public void RemoveConnectionsFromNonGlobalScenes(NetworkConnection[] conns)
Parameters
| Type | Name | Description |
|---|---|---|
| NetworkConnection[] | conns |
RemoveConnectionsFromScene(NetworkConnection[], Scene)
Removes connections from specified scenes. Exposed for power users, use caution.
Declaration
public void RemoveConnectionsFromScene(NetworkConnection[] conns, Scene scene)
Parameters
| Type | Name | Description |
|---|---|---|
| NetworkConnection[] | conns | Connections to remove. |
| UnityEngine.SceneManagement.Scene | scene | Scene to remove from. |
SetSceneProcessor(SceneProcessorBase)
Sets the SceneProcessor to use.
Declaration
public void SetSceneProcessor(SceneProcessorBase value)
Parameters
| Type | Name | Description |
|---|---|---|
| SceneProcessorBase | value |
UnloadConnectionScenes(NetworkConnection, SceneUnloadData)
Unloads scenes on server and tells a connection to unload them as well. Other connections will not unload this scene.
Declaration
public void UnloadConnectionScenes(NetworkConnection connection, SceneUnloadData sceneUnloadData)
Parameters
| Type | Name | Description |
|---|---|---|
| NetworkConnection | connection | Connection to unload scenes for. |
| SceneUnloadData | sceneUnloadData | Data about which scenes to unload. |
UnloadConnectionScenes(NetworkConnection[], SceneUnloadData)
Unloads scenes on server and tells connections to unload them as well. Other connections will not unload this scene.
Declaration
public void UnloadConnectionScenes(NetworkConnection[] connections, SceneUnloadData sceneUnloadData)
Parameters
| Type | Name | Description |
|---|---|---|
| NetworkConnection[] | connections | Connections to unload scenes for. |
| SceneUnloadData | sceneUnloadData | Data about which scenes to unload. |
UnloadConnectionScenes(SceneUnloadData)
Unloads scenes on server without telling any connections to unload them.
Declaration
public void UnloadConnectionScenes(SceneUnloadData sceneUnloadData)
Parameters
| Type | Name | Description |
|---|---|---|
| SceneUnloadData | sceneUnloadData | Data about which scenes to unload. |
UnloadGlobalScenes(SceneUnloadData)
Unloads scenes on the server and for all clients.
Declaration
public void UnloadGlobalScenes(SceneUnloadData sceneUnloadData)
Parameters
| Type | Name | Description |
|---|---|---|
| SceneUnloadData | sceneUnloadData | Data about which scenes to unload. |
Events
OnActiveSceneSet
Called after the active scene has been set, immediately after scene loads. This will occur before NetworkBehaviour callbacks run for the scene's objects. The boolean will indicate if the scene set active was specified by the user.
Declaration
public event Action<bool> OnActiveSceneSet
Event Type
| Type | Description |
|---|---|
| System.Action<System.Boolean> |
OnClientLoadedStartScenes
Called when a client loads initial scenes after connecting. Boolean will be true if asServer. This will invoke even if the SceneManager is not used when the client completes fully connecting to the server.
Declaration
public event Action<NetworkConnection, bool> OnClientLoadedStartScenes
Event Type
| Type | Description |
|---|---|
| System.Action<NetworkConnection, System.Boolean> |
OnClientPresenceChangeEnd
Called when a client presence changes within a scene, after the server rebuilds observers.
Declaration
public event Action<ClientPresenceChangeEventArgs> OnClientPresenceChangeEnd
Event Type
| Type | Description |
|---|---|
| System.Action<ClientPresenceChangeEventArgs> |
OnClientPresenceChangeStart
Called when a client presence changes within a scene, before the server rebuilds observers.
Declaration
public event Action<ClientPresenceChangeEventArgs> OnClientPresenceChangeStart
Event Type
| Type | Description |
|---|---|
| System.Action<ClientPresenceChangeEventArgs> |
OnLoadEnd
Called when a scene load ends.
Declaration
public event Action<SceneLoadEndEventArgs> OnLoadEnd
Event Type
| Type | Description |
|---|---|
| System.Action<SceneLoadEndEventArgs> |
OnLoadPercentChange
Called when completion percentage changes while loading a scene. Value is between 0f and 1f, while 1f is 100% done. Can be used for custom progress bars when loading scenes.
Declaration
public event Action<SceneLoadPercentEventArgs> OnLoadPercentChange
Event Type
| Type | Description |
|---|---|
| System.Action<SceneLoadPercentEventArgs> |
OnLoadStart
Called when a scene load starts.
Declaration
public event Action<SceneLoadStartEventArgs> OnLoadStart
Event Type
| Type | Description |
|---|---|
| System.Action<SceneLoadStartEventArgs> |
OnQueueEnd
Called when the scene queue is emptied.
Declaration
public event Action OnQueueEnd
Event Type
| Type | Description |
|---|---|
| System.Action |
OnQueueStart
Called when a scene change queue has begun. This will only call if a scene has succesfully begun to load or unload. The queue may process any number of scene events. For example: if a scene is told to unload while a load is still in progress, then the unload will be placed in the queue.
Declaration
public event Action OnQueueStart
Event Type
| Type | Description |
|---|---|
| System.Action |
OnUnloadEnd
Called when a scene unload ends.
Declaration
public event Action<SceneUnloadEndEventArgs> OnUnloadEnd
Event Type
| Type | Description |
|---|---|
| System.Action<SceneUnloadEndEventArgs> |
OnUnloadStart
Called when a scene unload starts.
Declaration
public event Action<SceneUnloadStartEventArgs> OnUnloadStart
Event Type
| Type | Description |
|---|---|
| System.Action<SceneUnloadStartEventArgs> |