Skip to content

Commit 3dea6aa

Browse files
committed
extending the interface to directly allow different injection patterns
1 parent 2b6befd commit 3dea6aa

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

com.unity.netcode.gameobjects/Runtime/Spawning/INetworkPrefabInstanceHandlerWithData.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,20 @@ internal class HandlerWrapper<T> : INetworkPrefabInstanceHandlerWithData where T
3232
public NetworkObject Instantiate(ulong ownerClientId, Vector3 position, Quaternion rotation) => _impl.Instantiate(ownerClientId, position, rotation, _payload);
3333
public void Destroy(NetworkObject networkObject) => _impl.Destroy(networkObject);
3434
}
35+
36+
37+
public static class INetworkPrefabInstanceHandlerWithDataExtensions
38+
{
39+
/// PLACEHOLDER: If this pattern is liked, i can move all the injection code to here instead of the PrefabHandler
40+
public static void InjectInstantiationData<T>(this INetworkPrefabInstanceHandlerWithData<T> handler, NetworkObject networkObject, T data) where T : struct, INetworkSerializable
41+
{
42+
NetworkManager.Singleton.PrefabHandler.InjectInstantiationData(networkObject, data);
43+
}
44+
45+
public static void SpawnWithData<T>(this INetworkPrefabInstanceHandlerWithData<T> handler, NetworkObject networkObject, T data) where T : struct, INetworkSerializable
46+
{
47+
InjectInstantiationData(handler, networkObject, data);
48+
networkObject.Spawn();
49+
}
50+
}
3551
}

0 commit comments

Comments
 (0)