Mirror::ClientScene
A client manager which contains static client information and functions. More...
Public Events
Name | |
---|---|
LocalplayerChanged | onLocalPlayerChanged() |
Public Functions
Name | |
---|---|
delegate void | LocalplayerChanged(NetworkIdentity oldPlayer, NetworkIdentity newPlayer) |
bool | AddPlayer(NetworkConnection readyConn) This adds a player GameObject for this client. This causes an AddPlayer message to be sent to the server, and NetworkManager.OnServerAddPlayer is called. |
bool | Ready(NetworkConnection conn) Signal that the client connection is ready to enter the game. |
void | PrepareToSpawnSceneObjects() Call this after loading/unloading a scene in the client after connection to register the spawnable objects |
bool | GetPrefab(Guid assetId, out GameObject prefab) Find the registered prefab for this asset id. Useful for debuggers |
void | RegisterPrefab(GameObject prefab, Guid newAssetId) Registers a prefab with the spawning system. |
void | RegisterPrefab(GameObject prefab) Registers a prefab with the spawning system. |
void | RegisterPrefab(GameObject prefab, Guid newAssetId, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler) Registers a prefab with the spawning system. |
void | RegisterPrefab(GameObject prefab, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler) Registers a prefab with the spawning system. |
void | RegisterPrefab(GameObject prefab, Guid newAssetId, SpawnHandlerDelegate spawnHandler, UnSpawnDelegate unspawnHandler) Registers a prefab with the spawning system. |
void | RegisterPrefab(GameObject prefab, SpawnHandlerDelegate spawnHandler, UnSpawnDelegate unspawnHandler) Registers a prefab with the spawning system. |
void | UnregisterPrefab(GameObject prefab) Removes a registered spawn prefab that was setup with ClientScene.RegisterPrefab. |
void | RegisterSpawnHandler(Guid assetId, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler) This is an advanced spawning function that registers a custom assetId with the UNET spawning system. |
void | RegisterSpawnHandler(Guid assetId, SpawnHandlerDelegate spawnHandler, UnSpawnDelegate unspawnHandler) This is an advanced spawning function that registers a custom assetId with the UNET spawning system. |
void | UnregisterSpawnHandler(Guid assetId) Removes a registered spawn handler function that was registered with ClientScene.RegisterHandler(). |
void | ClearSpawners() This clears the registered spawn prefabs and spawn handler functions for this client. |
void | DestroyAllClientObjects() Destroys all networked objects on the client. |
Public Properties
Name | |
---|---|
NetworkIdentity | localPlayer NetworkIdentity of the localPlayer |
bool | ready Returns true when a client's connection has been set to ready. |
NetworkConnection | readyConnection The NetworkConnection object that is currently "ready". This is the connection to the server where objects are spawned from. |
Public Attributes
Name | |
---|---|
readonly Dictionary< Guid, GameObject > | prefabs This is a dictionary of the prefabs that are registered on the client with ClientScene.RegisterPrefab(). |
readonly Dictionary< ulong, NetworkIdentity > | spawnableObjects This is dictionary of the disabled NetworkIdentity objects in the scene that could be spawned by messages from the server. |
Detailed Description
class Mirror::ClientScene;
A client manager which contains static client information and functions.
This manager contains references to tracked static local objects such as spawner registrations. It also has the default message handlers used by clients when they registered none themselves. The manager handles adding/removing player objects to the game after a client connection has been set as ready.
The ClientScene is a singleton, and it has static convenience methods such as ClientScene.Ready().
The ClientScene is used by the NetworkManager, but it can be used by itself.
As the ClientScene manages player objects on the client, it is where clients request to add players. The NetworkManager does this via the ClientScene automatically when auto-add-players is set, but it can be done through code using the function ClientScene.AddPlayer(). This sends an AddPlayer message to the server and will cause a player object to be created for this client.
Like NetworkServer, the ClientScene understands the concept of the local client. The function ClientScene.ConnectLocalServer() is used to become a host by starting a local client (when a server is already running).
Public Events Documentation
event onLocalPlayerChanged
static LocalplayerChanged onLocalPlayerChanged()
Public Functions Documentation
function LocalplayerChanged
delegate void LocalplayerChanged(
NetworkIdentity oldPlayer,
NetworkIdentity newPlayer
)
function AddPlayer
static inline bool AddPlayer(
NetworkConnection readyConn
)
This adds a player GameObject for this client. This causes an AddPlayer message to be sent to the server, and NetworkManager.OnServerAddPlayer is called.
Parameters:
- readyConn The connection to become ready for this client.
Return: True if AddPlayer message was sent
function Ready
static inline bool Ready(
NetworkConnection conn
)
Signal that the client connection is ready to enter the game.
Parameters:
- conn The client connection which is ready.
Return: True if succcessful
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 SYSTEM_READY event with an appropriate handler which instantiates the players object for example.
function PrepareToSpawnSceneObjects
static inline void PrepareToSpawnSceneObjects()
Call this after loading/unloading a scene in the client after connection to register the spawnable objects
function GetPrefab
static inline bool GetPrefab(
Guid assetId,
out GameObject prefab
)
Find the registered prefab for this asset id. Useful for debuggers
Parameters:
- assetId asset id of the prefab
- prefab the prefab gameobject
Return: true if prefab was registered
function RegisterPrefab
static inline void RegisterPrefab(
GameObject prefab,
Guid newAssetId
)
Registers a prefab with the spawning system.
Parameters:
- prefab A GameObject that will be spawned.
- newAssetId An assetId to be assigned to this GameObject. This allows a dynamically created game object to be registered for an already known asset Id.
When a NetworkIdentity object is spawned on a server with NetworkServer.SpawnObject(), and the prefab that the object was created from was registered with RegisterPrefab(), the client will use that prefab to instantiate a corresponding client object with the same netId.
The NetworkManager has a list of spawnable prefabs, it uses this function to register those prefabs with the ClientScene.
The set of current spawnable object is available in the ClientScene static member variable ClientScene.prefabs, which is a dictionary of NetworkAssetIds and prefab references.
NOTE: newAssetId can not be set on GameObjects that already have an assetId
function RegisterPrefab
static inline void RegisterPrefab(
GameObject prefab
)
Registers a prefab with the spawning system.
Parameters:
- prefab A Prefab that will be spawned.
When a NetworkIdentity object is spawned on a server with NetworkServer.SpawnObject(), and the prefab that the object was created from was registered with RegisterPrefab(), the client will use that prefab to instantiate a corresponding client object with the same netId.
The NetworkManager has a list of spawnable prefabs, it uses this function to register those prefabs with the ClientScene.
The set of current spawnable object is available in the ClientScene static member variable ClientScene.prefabs, which is a dictionary of NetworkAssetIds and prefab references.
function RegisterPrefab
static inline void RegisterPrefab(
GameObject prefab,
Guid newAssetId,
SpawnDelegate spawnHandler,
UnSpawnDelegate unspawnHandler
)
Registers a prefab with the spawning system.
Parameters:
- prefab A GameObject that will be spawned.
- newAssetId An assetId to be assigned to this GameObject. This allows a dynamically created game object to be registered for an already known asset Id.
- spawnHandler A method to use as a custom spawnhandler on clients.
- unspawnHandler A method to use as a custom un-spawnhandler on clients.
When a NetworkIdentity object is spawned on a server with NetworkServer.SpawnObject(), and the prefab that the object was created from was registered with RegisterPrefab(), the client will use that prefab to instantiate a corresponding client object with the same netId.
The NetworkManager has a list of spawnable prefabs, it uses this function to register those prefabs with the ClientScene.
The set of current spawnable object is available in the ClientScene static member variable ClientScene.prefabs, which is a dictionary of NetworkAssetIds and prefab references.
NOTE: newAssetId can not be set on GameObjects that already have an assetId
function RegisterPrefab
static inline void RegisterPrefab(
GameObject prefab,
SpawnDelegate spawnHandler,
UnSpawnDelegate unspawnHandler
)
Registers a prefab with the spawning system.
Parameters:
- prefab A Prefab that will be spawned.
- spawnHandler A method to use as a custom spawnhandler on clients.
- unspawnHandler A method to use as a custom un-spawnhandler on clients.
When a NetworkIdentity object is spawned on a server with NetworkServer.SpawnObject(), and the prefab that the object was created from was registered with RegisterPrefab(), the client will use that prefab to instantiate a corresponding client object with the same netId.
The NetworkManager has a list of spawnable prefabs, it uses this function to register those prefabs with the ClientScene.
The set of current spawnable object is available in the ClientScene static member variable ClientScene.prefabs, which is a dictionary of NetworkAssetIds and prefab references.
function RegisterPrefab
static inline void RegisterPrefab(
GameObject prefab,
Guid newAssetId,
SpawnHandlerDelegate spawnHandler,
UnSpawnDelegate unspawnHandler
)
Registers a prefab with the spawning system.
Parameters:
- prefab A GameObject that will be spawned.
- newAssetId An assetId to be assigned to this GameObject. This allows a dynamically created game object to be registered for an already known asset Id.
- spawnHandler A method to use as a custom spawnhandler on clients.
- unspawnHandler A method to use as a custom un-spawnhandler on clients.
When a NetworkIdentity object is spawned on a server with NetworkServer.SpawnObject(), and the prefab that the object was created from was registered with RegisterPrefab(), the client will use that prefab to instantiate a corresponding client object with the same netId.
The NetworkManager has a list of spawnable prefabs, it uses this function to register those prefabs with the ClientScene.
The set of current spawnable object is available in the ClientScene static member variable ClientScene.prefabs, which is a dictionary of NetworkAssetIds and prefab references.
NOTE: newAssetId can not be set on GameObjects that already have an assetId
function RegisterPrefab
static inline void RegisterPrefab(
GameObject prefab,
SpawnHandlerDelegate spawnHandler,
UnSpawnDelegate unspawnHandler
)
Registers a prefab with the spawning system.
Parameters:
- prefab A Prefab that will be spawned.
- spawnHandler A method to use as a custom spawnhandler on clients.
- unspawnHandler A method to use as a custom un-spawnhandler on clients.
When a NetworkIdentity object is spawned on a server with NetworkServer.SpawnObject(), and the prefab that the object was created from was registered with RegisterPrefab(), the client will use that prefab to instantiate a corresponding client object with the same netId.
The NetworkManager has a list of spawnable prefabs, it uses this function to register those prefabs with the ClientScene.
The set of current spawnable object is available in the ClientScene static member variable ClientScene.prefabs, which is a dictionary of NetworkAssetIds and prefab references.
function UnregisterPrefab
static inline void UnregisterPrefab(
GameObject prefab
)
Removes a registered spawn prefab that was setup with ClientScene.RegisterPrefab.
Parameters:
- prefab The prefab to be removed from registration.
function RegisterSpawnHandler
static inline void RegisterSpawnHandler(
Guid assetId,
SpawnDelegate spawnHandler,
UnSpawnDelegate unspawnHandler
)
This is an advanced spawning function that registers a custom assetId with the UNET spawning system.
Parameters:
- assetId Custom assetId string.
- spawnHandler A method to use as a custom spawnhandler on clients.
- unspawnHandler A method to use as a custom un-spawnhandler on clients.
This can be used to register custom spawning methods for an assetId - instead of the usual method of registering spawning methods for a prefab. This should be used when no prefab exists for the spawned objects - such as when they are constructed dynamically at runtime from configuration data.
function RegisterSpawnHandler
static inline void RegisterSpawnHandler(
Guid assetId,
SpawnHandlerDelegate spawnHandler,
UnSpawnDelegate unspawnHandler
)
This is an advanced spawning function that registers a custom assetId with the UNET spawning system.
Parameters:
- assetId Custom assetId string.
- spawnHandler A method to use as a custom spawnhandler on clients.
- unspawnHandler A method to use as a custom un-spawnhandler on clients.
This can be used to register custom spawning methods for an assetId - instead of the usual method of registering spawning methods for a prefab. This should be used when no prefab exists for the spawned objects - such as when they are constructed dynamically at runtime from configuration data.
function UnregisterSpawnHandler
static inline void UnregisterSpawnHandler(
Guid assetId
)
Removes a registered spawn handler function that was registered with ClientScene.RegisterHandler().
Parameters:
- assetId The assetId for the handler to be removed for.
function ClearSpawners
static inline void ClearSpawners()
This clears the registered spawn prefabs and spawn handler functions for this client.
function DestroyAllClientObjects
static inline void DestroyAllClientObjects()
Destroys all networked objects on the client.
This can be used to clean up when a network connection is closed.
Public Property Documentation
property localPlayer
static NetworkIdentity localPlayer;
NetworkIdentity of the localPlayer
property ready
static bool ready;
Returns true when a client's connection has been set to ready.
A client that is ready recieves state updates from the server, while a client that is not ready does not. This useful when the state of the game is not normal, such as a scene change or end-of-game.
This is read-only. To change the ready state of a client, use ClientScene.Ready(). The server is able to set the ready state of clients using NetworkServer.SetClientReady(), NetworkServer.SetClientNotReady() and NetworkServer.SetAllClientsNotReady().
This is done when changing scenes so that clients don't receive state update messages during scene loading.
property readyConnection
static NetworkConnection readyConnection;
The NetworkConnection object that is currently "ready". This is the connection to the server where objects are spawned from.
This connection can be used to send messages to the server. There can only be one ClientScene and ready connection at a time.
Public Attributes Documentation
variable prefabs
static readonly Dictionary< Guid, GameObject > prefabs = new Dictionary<Guid, GameObject>();
This is a dictionary of the prefabs that are registered on the client with ClientScene.RegisterPrefab().
The key to the dictionary is the prefab asset Id.
variable spawnableObjects
static readonly Dictionary< ulong, NetworkIdentity > spawnableObjects = new Dictionary<ulong, [NetworkIdentity](/Documentation/Cops%20And%20Robbers/Classes/classMirror_1_1NetworkIdentity/)>();
This is dictionary of the disabled NetworkIdentity objects in the scene that could be spawned by messages from the server.
The key to the dictionary is the NetworkIdentity sceneId.
Updated on 25 January 2021 at 09:57:16 UTC