Skip to content

Commit

Permalink
Remove redundant spawn handler (#476)
Browse files Browse the repository at this point in the history
One spawn handler delegate is enough

BREAKING CHANGE: Removed redundant spawn handler
  • Loading branch information
paulpach committed Nov 5, 2020
1 parent c5c48ce commit 9bbf0dc
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 36 deletions.
26 changes: 0 additions & 26 deletions Assets/Mirror/Runtime/ClientObjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,20 +222,6 @@ public void RegisterPrefab(GameObject prefab)
}
}

/// <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 ClientObjectManager 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 void RegisterPrefab(GameObject prefab, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
{
RegisterPrefab(prefab, msg => spawnHandler(msg.position, msg.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>
Expand Down Expand Up @@ -283,18 +269,6 @@ public void UnregisterPrefab(GameObject prefab)

#region Spawn Handler

/// <summary>
/// This is an advanced spawning function that registers a custom assetId with the UNET spawning system.
/// <para>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.</para>
/// </summary>
/// <param name="assetId">Custom assetId string.</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 void RegisterSpawnHandler(Guid assetId, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
{
RegisterSpawnHandler(assetId, msg => spawnHandler(msg.position, msg.assetId), unspawnHandler);
}

/// <summary>
/// This is an advanced spawning function that registers a custom assetId with the UNET spawning system.
/// <para>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.</para>
Expand Down
7 changes: 0 additions & 7 deletions Assets/Mirror/Runtime/INetworkClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

namespace Mirror
{
// Handles requests to spawn objects on the client
public delegate GameObject SpawnDelegate(Vector3 position, Guid assetId);

public delegate GameObject SpawnHandlerDelegate(SpawnMessage msg);

// Handles requests to unspawn objects on the client
Expand All @@ -20,14 +17,10 @@ public interface IClientObjectManager

void RegisterPrefab(GameObject prefab, Guid newAssetId);

void RegisterPrefab(GameObject prefab, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler);

void RegisterPrefab(GameObject prefab, SpawnHandlerDelegate spawnHandler, UnSpawnDelegate unspawnHandler);

void UnregisterPrefab(GameObject prefab);

void RegisterSpawnHandler(Guid assetId, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler);

void RegisterSpawnHandler(Guid assetId, SpawnHandlerDelegate spawnHandler, UnSpawnDelegate unspawnHandler);

void UnregisterSpawnHandler(Guid assetId);
Expand Down
2 changes: 1 addition & 1 deletion Assets/Tests/Runtime/ClientObjectManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void UnregisterSpawnHandlerTest()
Object.Destroy(prefabObject);
}

GameObject TestSpawnDelegate(Vector3 position, Guid assetId)
GameObject TestSpawnDelegate(SpawnMessage msg)
{
return new GameObject();
}
Expand Down
4 changes: 2 additions & 2 deletions Assets/Tests/Runtime/ClientServerComponentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ public void CheckNotHost()
});

int spawnDelegateTestCalled;
GameObject SpawnDelegateTest(Vector3 position, Guid assetId)
GameObject SpawnDelegateTest(SpawnMessage msg)
{
spawnDelegateTestCalled++;

GameObject prefab = clientObjectManager.GetPrefab(assetId);
GameObject prefab = clientObjectManager.GetPrefab(msg.assetId);
if (!(prefab is null))
{
return Object.Instantiate(prefab);
Expand Down

0 comments on commit 9bbf0dc

Please sign in to comment.