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
34 lines (28 loc) · 1.51 KB
/
INetworkPrefabInstanceHandlerWithData.cs
File metadata and controls
34 lines (28 loc) · 1.51 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
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 abstract class NetworkPrefabInstanceHandlerWithData<T> : INetworkPrefabInstanceHandlerWithData where T : struct, INetworkSerializable
{
public abstract NetworkObject Instantiate(ulong ownerClientId, Vector3 position, Quaternion rotation, T instantiationData);
public abstract void Destroy(NetworkObject networkObject);
bool INetworkPrefabInstanceHandlerWithData.HandlesDataType<U>() => typeof(T) == typeof(U);
NetworkObject INetworkPrefabInstanceHandlerWithData.Instantiate(ulong ownerClientId, Vector3 position, Quaternion rotation, FastBufferReader reader)
{
reader.ReadValueSafe(out T _payload);
return Instantiate(ownerClientId, position, rotation, _payload);
}
NetworkObject INetworkPrefabInstanceHandler.Instantiate(ulong ownerClientId, Vector3 position, Quaternion rotation) => Instantiate(ownerClientId, position, rotation, default);
}
internal interface INetworkPrefabInstanceHandlerWithData : INetworkPrefabInstanceHandler
{
bool HandlesDataType<T>();
NetworkObject Instantiate(ulong ownerClientId, Vector3 position, Quaternion rotation, FastBufferReader reader);
}
}