Skip to content

Commit

Permalink
fix(ClientObjectManager): add prefab to SpawnHandler when registering (
Browse files Browse the repository at this point in the history
  • Loading branch information
GeekBrony authored Feb 16, 2024
1 parent 202d71e commit 7a8ff46
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions Assets/Mirage/Runtime/ClientObjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,10 @@ public void UnregisterPrefab(NetworkIdentity identity)
/// <param name="unspawnHandler">A method to use as a custom un-spawnhandler on clients.</param>
public void RegisterSpawnHandler(NetworkIdentity identity, SpawnHandlerDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
{
ThrowIfZeroHash(identity);
var prefabHash = identity.PrefabHash;
RegisterSpawnHandler(prefabHash, spawnHandler, unspawnHandler);
ValidateRegisterSpawnHandler(prefabHash, spawnHandler, unspawnHandler);

_handlers[prefabHash] = new SpawnHandler(identity, spawnHandler, unspawnHandler);
}

/// <summary>
Expand All @@ -322,9 +323,10 @@ public void RegisterSpawnHandler(int prefabHash, SpawnHandlerDelegate spawnHandl

public void RegisterSpawnHandler(NetworkIdentity identity, SpawnHandlerAsyncDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
{
ThrowIfZeroHash(identity);
var prefabHash = identity.PrefabHash;
RegisterSpawnHandler(prefabHash, spawnHandler, unspawnHandler);
ValidateRegisterSpawnHandler(prefabHash, spawnHandler, unspawnHandler);

_handlers[prefabHash] = new SpawnHandler(identity, spawnHandler, unspawnHandler);
}

public void RegisterSpawnHandler(int prefabHash, SpawnHandlerAsyncDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
Expand Down Expand Up @@ -784,13 +786,29 @@ public SpawnHandler(SpawnHandlerDelegate spawnHandler, UnSpawnDelegate unspawnHa
UnspawnHandler = unspawnHandler;
}

public SpawnHandler(NetworkIdentity prefab, SpawnHandlerDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
{
Prefab = prefab ?? throw new ArgumentNullException(nameof(prefab));
Handler = spawnHandler ?? throw new ArgumentNullException(nameof(spawnHandler));
// unspawn is allowed to be null
UnspawnHandler = unspawnHandler;
}

public SpawnHandler(SpawnHandlerAsyncDelegate spawnHandlerAsync, UnSpawnDelegate unspawnHandler)
{
HandlerAsync = spawnHandlerAsync ?? throw new ArgumentNullException(nameof(spawnHandlerAsync));
// unspawn is allowed to be null
UnspawnHandler = unspawnHandler;
}

public SpawnHandler(NetworkIdentity prefab, SpawnHandlerAsyncDelegate spawnHandlerAsync, UnSpawnDelegate unspawnHandler)
{
Prefab = prefab ?? throw new ArgumentNullException(nameof(prefab));
HandlerAsync = spawnHandlerAsync ?? throw new ArgumentNullException(nameof(spawnHandlerAsync));
// unspawn is allowed to be null
UnspawnHandler = unspawnHandler;
}

public void AddUnspawnHandler(UnSpawnDelegate unspawnHandler)
{
if (Prefab == null)
Expand Down

0 comments on commit 7a8ff46

Please sign in to comment.