mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
Remove ClientScene.RegisterPrefab with Spawn/UnspawnHandlerDelegate
This commit is contained in:
parent
0aeb13a8af
commit
c54be229a8
@ -393,79 +393,6 @@ public static void RegisterPrefab(GameObject prefab, Guid newAssetId, SpawnHandl
|
|||||||
unspawnHandlers[assetId] = unspawnHandler;
|
unspawnHandlers[assetId] = unspawnHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Registers a prefab with the spawning system.
|
|
||||||
/// <para>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.</para>
|
|
||||||
/// <para>The NetworkManager has a list of spawnable prefabs, it uses this function to register those prefabs with the ClientScene.</para>
|
|
||||||
/// <para>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.</para>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="prefab">A Prefab that will be spawned.</param>
|
|
||||||
/// <param name="spawnHandler">A method to use as a custom spawnhandler on clients.</param>
|
|
||||||
/// <param name="unspawnHandler">A method to use as a custom un-spawnhandler on clients.</param>
|
|
||||||
public static void RegisterPrefab(GameObject prefab, SpawnHandlerDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
|
|
||||||
{
|
|
||||||
if (prefab == null)
|
|
||||||
{
|
|
||||||
Debug.LogError("Could not register handler for prefab because the prefab was null");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
NetworkIdentity identity = prefab.GetComponent<NetworkIdentity>();
|
|
||||||
if (identity == null)
|
|
||||||
{
|
|
||||||
Debug.LogError("Could not register handler for '" + prefab.name + "' since it contains no NetworkIdentity component");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (identity.sceneId != 0)
|
|
||||||
{
|
|
||||||
Debug.LogError($"Can not Register '{prefab.name}' because it has a sceneId, make sure you are passing in the original prefab and not an instance in the scene.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Guid assetId = identity.assetId;
|
|
||||||
|
|
||||||
if (assetId == Guid.Empty)
|
|
||||||
{
|
|
||||||
Debug.LogError($"Can not Register handler for '{prefab.name}' because it had empty assetid. If this is a scene Object use RegisterSpawnHandler instead");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (spawnHandler == null)
|
|
||||||
{
|
|
||||||
Debug.LogError($"Can not Register null SpawnHandler for {assetId}");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unspawnHandler == null)
|
|
||||||
{
|
|
||||||
Debug.LogError($"Can not Register null UnSpawnHandler for {assetId}");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (spawnHandlers.ContainsKey(assetId) || unspawnHandlers.ContainsKey(assetId))
|
|
||||||
{
|
|
||||||
Debug.LogWarning($"Replacing existing spawnHandlers for prefab '{prefab.name}' with assetId '{assetId}'");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prefabs.ContainsKey(assetId))
|
|
||||||
{
|
|
||||||
// this is error because SpawnPrefab checks prefabs before handler
|
|
||||||
Debug.LogError($"assetId '{assetId}' is already used by prefab '{prefabs[assetId].name}', unregister the prefab first before trying to add handler");
|
|
||||||
}
|
|
||||||
|
|
||||||
NetworkIdentity[] identities = prefab.GetComponentsInChildren<NetworkIdentity>();
|
|
||||||
if (identities.Length > 1)
|
|
||||||
{
|
|
||||||
Debug.LogWarning($"Prefab '{prefab.name}' has multiple NetworkIdentity components. There should only be one NetworkIdentity on a prefab, and it must be on the root object.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Debug.Log("Registering custom prefab '" + prefab.name + "' as asset:" + assetId + " " + spawnHandler.GetMethodName() + "/" + unspawnHandler.GetMethodName());
|
|
||||||
|
|
||||||
spawnHandlers[assetId] = spawnHandler;
|
|
||||||
unspawnHandlers[assetId] = unspawnHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Removes a registered spawn prefab that was setup with ClientScene.RegisterPrefab.
|
/// Removes a registered spawn prefab that was setup with ClientScene.RegisterPrefab.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user