Skip to main content

Class ClientObjectManager

Inheritance
System.Object
Syntax
public class ClientObjectManager : MonoBehaviour

Fields

spawnPrefabs

List of prefabs that will be registered with the spawning system. For each of these prefabs, ClientManager.RegisterPrefab() will be automatically invoke.

Declaration
public List<NetworkIdentity> spawnPrefabs

NetworkPrefabs

A scriptable object that holds all the prefabs that will be registered with the spawning system. For each of these prefabs, ClientManager.RegisterPrefab() will be automatically invoked.

Declaration
public NetworkPrefabs NetworkPrefabs

spawnableObjects

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.

Declaration
public readonly Dictionary<ulong, NetworkIdentity> spawnableObjects

Properties

Client

Declaration
public NetworkClient Client { get; }

Methods

PrepareToSpawnSceneObjects()

Call this after loading/unloading a scene in the client after connection to register the spawnable objects

Declaration
public void PrepareToSpawnSceneObjects()

RegisterPrefabs(IEnumerable<NetworkIdentity>, Boolean)

Calls on each object in the prefabs collection

Declaration
public void RegisterPrefabs(IEnumerable<NetworkIdentity> prefabs, bool skipExisting)
Parameters
TypeNameDescription
System.Collections.Generic.IEnumerable<Mirage.NetworkIdentity>prefabs
System.BooleanskipExistingDont call for prefab's who's hash is already in the list of handlers. This can happen if custom handler is added for a prefab in the insepctor list

GetSpawnHandler(Int32)

Find the registered or dynamic handler for prefabHash Useful for debuggers

Declaration
public SpawnHandler GetSpawnHandler(int prefabHash)
Parameters
TypeNameDescription
System.Int32prefabHashasset id of the prefab
Returns
TypeDescription
Mirage.SpawnHandlertrue if prefab was registered

RegisterPrefab(NetworkIdentity, Int32)

Registers a prefab with the spawning system.

When a NetworkIdentity object is spawned on the server with ServerObjectManager.Spawn(), the server will send a spawn message to the client with the PrefabHash. the client then finds the prefab registered with RegisterPrefab() to instantiate the client object.

The ClientObjectManager 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 PrefabHash and prefab references.

Declaration
public void RegisterPrefab(NetworkIdentity identity, int newPrefabHash)
Parameters
TypeNameDescription
Mirage.NetworkIdentityidentityA Prefab that will be spawned.
System.Int32newPrefabHashA hash to be assigned to this prefab. This allows a dynamically created game object to be registered for an already known asset Id.

RegisterPrefab(NetworkIdentity)

Registers a prefab with the spawning system.

When a NetworkIdentity object is spawned on the server with ServerObjectManager.Spawn(), the server will send a spawn message to the client with the PrefabHash. the client then finds the prefab registered with RegisterPrefab() to instantiate the client object.

The ClientObjectManager 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 PrefabHash and prefab references.

Declaration
public void RegisterPrefab(NetworkIdentity identity)
Parameters
TypeNameDescription
Mirage.NetworkIdentityidentityA Prefab that will be spawned.

RegisterUnspawnHandler(NetworkIdentity, UnSpawnDelegate)

Registers an unspawn handler for a prefab Should be called after RegisterPrefab

Declaration
public void RegisterUnspawnHandler(NetworkIdentity identity, UnSpawnDelegate unspawnHandler)
Parameters
TypeNameDescription
Mirage.NetworkIdentityidentityPrefab to add handler for
Mirage.UnSpawnDelegateunspawnHandlerA method to use as a custom un-spawnhandler on clients.

UnregisterPrefab(NetworkIdentity)

Removes a registered spawn prefab that was setup with ClientScene.RegisterPrefab.

Declaration
public void UnregisterPrefab(NetworkIdentity identity)
Parameters
TypeNameDescription
Mirage.NetworkIdentityidentityThe prefab to be removed from registration.

RegisterSpawnHandler(NetworkIdentity, SpawnHandlerDelegate, UnSpawnDelegate)

Registers custom handlers for a prefab with the spawning system.

When a NetworkIdentity object is spawned on the server with ServerObjectManager.Spawn(), the server will send a spawn message to the client with the PrefabHash. the client then finds the prefab registered with RegisterPrefab() to instantiate the client object.

The ClientObjectManager 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 PrefabHash and prefab references.

Declaration
public void RegisterSpawnHandler(NetworkIdentity identity, SpawnHandlerDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
Parameters
TypeNameDescription
Mirage.NetworkIdentityidentityA Prefab that will be spawned.
Mirage.SpawnHandlerDelegatespawnHandlerA method to use as a custom spawnhandler on clients.
Mirage.UnSpawnDelegateunspawnHandlerA method to use as a custom un-spawnhandler on clients.

RegisterSpawnHandler(Int32, SpawnHandlerDelegate, UnSpawnDelegate)

This is an advanced spawning function that registers a custom prefabHash with the UNET spawning system. This can be used to register custom spawning methods for an prefabHash - 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.

Declaration
public void RegisterSpawnHandler(int prefabHash, SpawnHandlerDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
Parameters
TypeNameDescription
System.Int32prefabHash
Mirage.SpawnHandlerDelegatespawnHandlerA method to use as a custom spawnhandler on clients.
Mirage.UnSpawnDelegateunspawnHandlerA method to use as a custom un-spawnhandler on clients.

RegisterSpawnHandler(NetworkIdentity, SpawnHandlerAsyncDelegate, UnSpawnDelegate)

Declaration
public void RegisterSpawnHandler(NetworkIdentity identity, SpawnHandlerAsyncDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
Parameters
TypeNameDescription
Mirage.NetworkIdentityidentity
Mirage.SpawnHandlerAsyncDelegatespawnHandler
Mirage.UnSpawnDelegateunspawnHandler

RegisterSpawnHandler(Int32, SpawnHandlerAsyncDelegate, UnSpawnDelegate)

Declaration
public void RegisterSpawnHandler(int prefabHash, SpawnHandlerAsyncDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
Parameters
TypeNameDescription
System.Int32prefabHash
Mirage.SpawnHandlerAsyncDelegatespawnHandler
Mirage.UnSpawnDelegateunspawnHandler

UnregisterSpawnHandler(Int32)

Removes a registered spawn handler function that was registered with ClientScene.RegisterHandler().

Declaration
public void UnregisterSpawnHandler(int prefabHash)
Parameters
TypeNameDescription
System.Int32prefabHashThe prefabHash for the handler to be removed for.

ClearSpawners()

This clears the registered spawn prefabs and spawn handler functions for this client.

Declaration
public void ClearSpawners()

RegisterDynamicSpawnHandler(DynamicSpawnHandlerDelegate)

Declaration
public void RegisterDynamicSpawnHandler(DynamicSpawnHandlerDelegate dynamicHandler)
Parameters
TypeNameDescription
Mirage.DynamicSpawnHandlerDelegatedynamicHandler

DestroyAllClientObjects()

Destroys all networked objects on the client. This can be used to clean up when a network connection is closed.

Declaration
public void DestroyAllClientObjects()