forked from Unity-Technologies/com.unity.netcode.gameobjects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathINetworkPrefabInstanceHandlerWithData.cs
More file actions
41 lines (34 loc) · 1.73 KB
/
INetworkPrefabInstanceHandlerWithData.cs
File metadata and controls
41 lines (34 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.Collections.Generic;
using Unity.Collections;
using UnityEngine;
namespace Unity.Netcode
{
/// <summary>
/// Specialized version of <see cref="INetworkPrefabInstanceHandler"/> that receives
/// custom instantiation data injected by the server before spawning.
/// </summary>
public interface INetworkPrefabInstanceHandlerWithData<T> where T : struct, INetworkSerializable
{
NetworkObject Instantiate(ulong ownerClientId, Vector3 position, Quaternion rotation, T instantiationData);
void Destroy(NetworkObject networkObject);
}
internal interface INetworkPrefabInstanceHandlerWithData : INetworkPrefabInstanceHandler
{
NetworkObject Instantiate(ulong ownerClientId, Vector3 position, Quaternion rotation, FastBufferReader reader);
bool HandlesDataType<T>();
}
internal class HandlerWrapper<T> : INetworkPrefabInstanceHandlerWithData where T : struct, INetworkSerializable
{
private readonly INetworkPrefabInstanceHandlerWithData<T> _impl;
public HandlerWrapper(INetworkPrefabInstanceHandlerWithData<T> impl) => _impl = impl;
public bool HandlesDataType<U>() => typeof(T) == typeof(U);
public NetworkObject Instantiate(ulong ownerClientId, Vector3 position, Quaternion rotation, FastBufferReader reader)
{
reader.ReadValueSafe(out T _payload);
return _impl.Instantiate(ownerClientId, position, rotation, _payload);
}
public NetworkObject Instantiate(ulong ownerClientId, Vector3 position, Quaternion rotation) => _impl.Instantiate(ownerClientId, position, rotation, default);
public void Destroy(NetworkObject networkObject) => _impl.Destroy(networkObject);
}
}