com.unity.netcode.gameobjects@2.0.0-pre.3
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). Additional documentation and release notes are available at [Multiplayer Documentation](https://docs-multiplayer.unity3d.com). ## [2.0.0-pre.3] - 2024-07-23 ### Added - Added: `UnityTransport.GetNetworkDriver` and `UnityTransport.GetLocalEndpoint` methods to expose the driver and local endpoint being used. (#2978) ### Fixed - Fixed issue where deferred despawn was causing GC allocations when converting an `IEnumerable` to a list. (#2983) - Fixed issue where the realtime network stats monitor was not able to display RPC traffic in release builds due to those stats being only available in development builds or the editor. (#2979) - Fixed issue where `NetworkManager.ScenesLoaded` was not being updated if `PostSynchronizationSceneUnloading` was set and any loaded scenes not used during synchronization were unloaded. (#2971) - Fixed issue where `Rigidbody2d` under Unity 6000.0.11f1 has breaking changes where `velocity` is now `linearVelocity` and `isKinematic` is replaced by `bodyType`. (#2971) - Fixed issue where `NetworkSpawnManager.InstantiateAndSpawn` and `NetworkObject.InstantiateAndSpawn` were not honoring the ownerClientId parameter when using a client-server network topology. (#2968) - Fixed issue where internal delta serialization could not have a byte serializer defined when serializing deltas for other types. Added `[GenerateSerializationForType(typeof(byte))]` to both the `NetworkVariable` and `AnticipatedNetworkVariable` classes to assure a byte serializer is defined.(#2962) - Fixed issue when scene management was disabled and the session owner would still try to synchronize a late joining client. (#2962) - Fixed issue when using a distributed authority network topology where it would allow a session owner to spawn a `NetworkObject` prior to being approved. Now, an error message is logged and the `NetworkObject` will not be spawned prior to the client being approved. (#2962) - Fixed issue where attempting to spawn during `NetworkBehaviour.OnInSceneObjectsSpawned` and `NetworkBehaviour.OnNetworkSessionSynchronized` notifications would throw a collection modified exception. (#2962) ### Changed - Changed logic where clients can now set the `NetworkSceneManager` client synchronization mode when using a distributed authority network topology. (#2985)
This commit is contained in:
@@ -51,6 +51,7 @@ namespace Unity.Netcode
|
||||
#pragma warning restore IDE0001
|
||||
[Serializable]
|
||||
[GenerateSerializationForGenericParameter(0)]
|
||||
[GenerateSerializationForType(typeof(byte))]
|
||||
public class AnticipatedNetworkVariable<T> : NetworkVariableBase
|
||||
{
|
||||
[SerializeField]
|
||||
|
||||
@@ -94,18 +94,18 @@ namespace Unity.Netcode
|
||||
{
|
||||
case NetworkListEvent<T>.EventType.Add:
|
||||
{
|
||||
NetworkVariableSerialization<T>.Write(writer, ref element.Value);
|
||||
NetworkVariableSerialization<T>.Serializer.Write(writer, ref element.Value);
|
||||
}
|
||||
break;
|
||||
case NetworkListEvent<T>.EventType.Insert:
|
||||
{
|
||||
BytePacker.WriteValueBitPacked(writer, element.Index);
|
||||
NetworkVariableSerialization<T>.Write(writer, ref element.Value);
|
||||
NetworkVariableSerialization<T>.Serializer.Write(writer, ref element.Value);
|
||||
}
|
||||
break;
|
||||
case NetworkListEvent<T>.EventType.Remove:
|
||||
{
|
||||
NetworkVariableSerialization<T>.Write(writer, ref element.Value);
|
||||
NetworkVariableSerialization<T>.Serializer.Write(writer, ref element.Value);
|
||||
}
|
||||
break;
|
||||
case NetworkListEvent<T>.EventType.RemoveAt:
|
||||
@@ -116,7 +116,7 @@ namespace Unity.Netcode
|
||||
case NetworkListEvent<T>.EventType.Value:
|
||||
{
|
||||
BytePacker.WriteValueBitPacked(writer, element.Index);
|
||||
NetworkVariableSerialization<T>.Write(writer, ref element.Value);
|
||||
NetworkVariableSerialization<T>.Serializer.Write(writer, ref element.Value);
|
||||
}
|
||||
break;
|
||||
case NetworkListEvent<T>.EventType.Clear:
|
||||
@@ -133,13 +133,13 @@ namespace Unity.Netcode
|
||||
{
|
||||
if (m_NetworkManager.DistributedAuthorityMode)
|
||||
{
|
||||
writer.WriteValueSafe(NetworkVariableSerialization<T>.Type);
|
||||
if (NetworkVariableSerialization<T>.Type == CollectionItemType.Unmanaged)
|
||||
writer.WriteValueSafe(NetworkVariableSerialization<T>.Serializer.Type);
|
||||
if (NetworkVariableSerialization<T>.Serializer.Type == NetworkVariableType.Unmanaged)
|
||||
{
|
||||
// Write the size of the unmanaged serialized type as it has a fixed size. This allows the CMB runtime to correctly read the unmanged type.
|
||||
var placeholder = new T();
|
||||
var startPos = writer.Position;
|
||||
NetworkVariableSerialization<T>.Write(writer, ref placeholder);
|
||||
NetworkVariableSerialization<T>.Serializer.Write(writer, ref placeholder);
|
||||
var size = writer.Position - startPos;
|
||||
writer.Seek(startPos);
|
||||
BytePacker.WriteValueBitPacked(writer, size);
|
||||
@@ -148,7 +148,7 @@ namespace Unity.Netcode
|
||||
writer.WriteValueSafe((ushort)m_List.Length);
|
||||
for (int i = 0; i < m_List.Length; i++)
|
||||
{
|
||||
NetworkVariableSerialization<T>.Write(writer, ref m_List.ElementAt(i));
|
||||
NetworkVariableSerialization<T>.Serializer.Write(writer, ref m_List.ElementAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,9 +158,9 @@ namespace Unity.Netcode
|
||||
m_List.Clear();
|
||||
if (m_NetworkManager.DistributedAuthorityMode)
|
||||
{
|
||||
// Collection item type is used by the CMB rust service, drop value here.
|
||||
reader.ReadValueSafe(out CollectionItemType type);
|
||||
if (type == CollectionItemType.Unmanaged)
|
||||
SerializationTools.ReadType(reader, NetworkVariableSerialization<T>.Serializer);
|
||||
// Collection item type is used by the DA server, drop value here.
|
||||
if (NetworkVariableSerialization<T>.Serializer.Type == NetworkVariableType.Unmanaged)
|
||||
{
|
||||
ByteUnpacker.ReadValueBitPacked(reader, out int _);
|
||||
}
|
||||
@@ -169,7 +169,7 @@ namespace Unity.Netcode
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var value = new T();
|
||||
NetworkVariableSerialization<T>.Read(reader, ref value);
|
||||
NetworkVariableSerialization<T>.Serializer.Read(reader, ref value);
|
||||
m_List.Add(value);
|
||||
}
|
||||
}
|
||||
@@ -186,7 +186,7 @@ namespace Unity.Netcode
|
||||
case NetworkListEvent<T>.EventType.Add:
|
||||
{
|
||||
var value = new T();
|
||||
NetworkVariableSerialization<T>.Read(reader, ref value);
|
||||
NetworkVariableSerialization<T>.Serializer.Read(reader, ref value);
|
||||
m_List.Add(value);
|
||||
|
||||
if (OnListChanged != null)
|
||||
@@ -215,7 +215,7 @@ namespace Unity.Netcode
|
||||
{
|
||||
ByteUnpacker.ReadValueBitPacked(reader, out int index);
|
||||
var value = new T();
|
||||
NetworkVariableSerialization<T>.Read(reader, ref value);
|
||||
NetworkVariableSerialization<T>.Serializer.Read(reader, ref value);
|
||||
|
||||
if (index < m_List.Length)
|
||||
{
|
||||
@@ -252,7 +252,7 @@ namespace Unity.Netcode
|
||||
case NetworkListEvent<T>.EventType.Remove:
|
||||
{
|
||||
var value = new T();
|
||||
NetworkVariableSerialization<T>.Read(reader, ref value);
|
||||
NetworkVariableSerialization<T>.Serializer.Read(reader, ref value);
|
||||
int index = m_List.IndexOf(value);
|
||||
if (index == -1)
|
||||
{
|
||||
@@ -315,7 +315,7 @@ namespace Unity.Netcode
|
||||
{
|
||||
ByteUnpacker.ReadValueBitPacked(reader, out int index);
|
||||
var value = new T();
|
||||
NetworkVariableSerialization<T>.Read(reader, ref value);
|
||||
NetworkVariableSerialization<T>.Serializer.Read(reader, ref value);
|
||||
if (index >= m_List.Length)
|
||||
{
|
||||
throw new Exception("Shouldn't be here, index is higher than list length");
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace Unity.Netcode
|
||||
/// <typeparam name="T">the unmanaged type for <see cref="NetworkVariable{T}"/> </typeparam>
|
||||
[Serializable]
|
||||
[GenerateSerializationForGenericParameter(0)]
|
||||
[GenerateSerializationForType(typeof(byte))]
|
||||
public class NetworkVariable<T> : NetworkVariableBase
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Unity.Netcode
|
||||
|
||||
private NetworkManager m_InternalNetworkManager;
|
||||
|
||||
internal virtual NetworkVariableType Type => NetworkVariableType.Custom;
|
||||
internal virtual NetworkVariableType Type => NetworkVariableType.Unknown;
|
||||
|
||||
private protected NetworkManager m_NetworkManager
|
||||
{
|
||||
@@ -311,7 +311,6 @@ namespace Unity.Netcode
|
||||
/// </summary>
|
||||
/// <param name="reader">The stream to read the state from</param>
|
||||
public abstract void ReadField(FastBufferReader reader);
|
||||
|
||||
/// <summary>
|
||||
/// Reads delta from the reader and applies them to the internal value
|
||||
/// </summary>
|
||||
@@ -327,47 +326,4 @@ namespace Unity.Netcode
|
||||
m_InternalNetworkManager = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enum representing the different types of Network Variables.
|
||||
/// </summary>
|
||||
public enum NetworkVariableType : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// Value
|
||||
/// Used for all of the basic NetworkVariables that contain a single value
|
||||
/// </summary>
|
||||
Value = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Custom
|
||||
/// For any custom implemented extension of the NetworkVariableBase
|
||||
/// </summary>
|
||||
Custom = 1,
|
||||
|
||||
/// <summary>
|
||||
/// NetworkList
|
||||
/// </summary>
|
||||
NetworkList = 2
|
||||
}
|
||||
|
||||
public enum CollectionItemType : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// For any type that is not valid inside a NetworkVariable collection
|
||||
/// </summary>
|
||||
Unknown = 0,
|
||||
|
||||
/// <summary>
|
||||
/// The following types are valid types inside of NetworkVariable collections
|
||||
/// </summary>
|
||||
Short = 1,
|
||||
UShort = 2,
|
||||
Int = 3,
|
||||
UInt = 4,
|
||||
Long = 5,
|
||||
ULong = 6,
|
||||
Unmanaged = 7,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
40
Runtime/NetworkVariable/NetworkVariableTypes.cs
Normal file
40
Runtime/NetworkVariable/NetworkVariableTypes.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
#if UNITY_EDITOR
|
||||
#endif
|
||||
|
||||
namespace Unity.Netcode
|
||||
{
|
||||
/// <summary>
|
||||
/// Enum representing the different types of Network Variables that can be sent over the network.
|
||||
/// The values cannot be changed, as they are used to serialize and deserialize variables on the DA server.
|
||||
/// Adding new variables should be done by adding new values to the end of the enum
|
||||
/// using the next free value.
|
||||
/// </summary>
|
||||
/// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
/// Add any new Variable types to this table at the END with incremented index value
|
||||
/// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
internal enum NetworkVariableType : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// Value
|
||||
/// Used for all of the basic NetworkVariables that contain a single value
|
||||
/// </summary>
|
||||
Value = 0,
|
||||
/// <summary>
|
||||
/// For any type that is not known at runtime
|
||||
/// </summary>
|
||||
Unknown = 1,
|
||||
/// <summary>
|
||||
/// NetworkList
|
||||
/// </summary>
|
||||
NetworkList = 2,
|
||||
|
||||
// The following types are valid types inside of NetworkVariable collections
|
||||
Short = 11,
|
||||
UShort = 12,
|
||||
Int = 13,
|
||||
UInt = 14,
|
||||
Long = 15,
|
||||
ULong = 16,
|
||||
Unmanaged = 17,
|
||||
}
|
||||
}
|
||||
3
Runtime/NetworkVariable/NetworkVariableTypes.cs.meta
Normal file
3
Runtime/NetworkVariable/NetworkVariableTypes.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df4a4005f1c842669f94a404019400ed
|
||||
timeCreated: 1718292058
|
||||
@@ -14,6 +14,9 @@ namespace Unity.Netcode
|
||||
/// <typeparam name="T"></typeparam>
|
||||
internal class FallbackSerializer<T> : INetworkVariableSerializer<T>
|
||||
{
|
||||
public NetworkVariableType Type => NetworkVariableType.Unknown;
|
||||
public bool IsDistributedAuthorityOptimized => true;
|
||||
|
||||
private void ThrowArgumentError()
|
||||
{
|
||||
throw new ArgumentException($"Serialization has not been generated for type {typeof(T).FullName}. This can be addressed by adding a [{nameof(GenerateSerializationForGenericParameterAttribute)}] to your generic class that serializes this value (if you are using one), adding [{nameof(GenerateSerializationForTypeAttribute)}(typeof({typeof(T).FullName})] to the class or method that is attempting to serialize it, or creating a field on a {nameof(NetworkBehaviour)} of type {nameof(NetworkVariable<T>)}. If this error continues to appear after doing one of those things and this is a type you can change, then either implement {nameof(INetworkSerializable)} or mark it as serializable by memcpy by adding {nameof(INetworkSerializeByMemcpy)} to its interface list to enable automatic serialization generation. If not, assign serialization code to {nameof(UserNetworkVariableSerialization<T>)}.{nameof(UserNetworkVariableSerialization<T>.WriteValue)}, {nameof(UserNetworkVariableSerialization<T>)}.{nameof(UserNetworkVariableSerialization<T>.ReadValue)}, and {nameof(UserNetworkVariableSerialization<T>)}.{nameof(UserNetworkVariableSerialization<T>.DuplicateValue)}, or if it's serializable by memcpy (contains no pointers), wrap it in {typeof(ForceNetworkSerializeByMemcpy<>).Name}.");
|
||||
@@ -79,6 +82,11 @@ namespace Unity.Netcode
|
||||
}
|
||||
UserNetworkVariableSerialization<T>.DuplicateValue(value, ref duplicatedValue);
|
||||
}
|
||||
|
||||
public void WriteDistributedAuthority(FastBufferWriter writer, ref T value) => ThrowArgumentError();
|
||||
public void ReadDistributedAuthority(FastBufferReader reader, ref T value) => ThrowArgumentError();
|
||||
public void WriteDeltaDistributedAuthority(FastBufferWriter writer, ref T value, ref T previousValue) => ThrowArgumentError();
|
||||
public void ReadDeltaDistributedAuthority(FastBufferReader reader, ref T value) => ThrowArgumentError();
|
||||
}
|
||||
|
||||
// RuntimeAccessModifiersILPP will make this `public`
|
||||
|
||||
@@ -3,11 +3,27 @@ using Unity.Collections;
|
||||
namespace Unity.Netcode
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface used by NetworkVariables to serialize them
|
||||
/// Interface used by NetworkVariables to serialize them with additional information for the DA runtime
|
||||
/// </summary>
|
||||
///
|
||||
/// <typeparam name="T"></typeparam>
|
||||
internal interface INetworkVariableSerializer<T>
|
||||
internal interface IDistributedAuthoritySerializer<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// The Type tells the DA server how to parse this type.
|
||||
/// The user should never be able to override this value, as it is meaningful for the DA server
|
||||
/// </summary>
|
||||
public NetworkVariableType Type { get; }
|
||||
public bool IsDistributedAuthorityOptimized { get; }
|
||||
public void WriteDistributedAuthority(FastBufferWriter writer, ref T value);
|
||||
public void ReadDistributedAuthority(FastBufferReader reader, ref T value);
|
||||
public void WriteDeltaDistributedAuthority(FastBufferWriter writer, ref T value, ref T previousValue);
|
||||
public void ReadDeltaDistributedAuthority(FastBufferReader reader, ref T value);
|
||||
}
|
||||
|
||||
|
||||
/// <typeparam name="T"></typeparam>
|
||||
internal interface INetworkVariableSerializer<T> : IDistributedAuthoritySerializer<T>
|
||||
{
|
||||
// Write has to be taken by ref here because of INetworkSerializable
|
||||
// Open Instance Delegates (pointers to methods without an instance attached to them)
|
||||
|
||||
@@ -16,12 +16,6 @@ namespace Unity.Netcode
|
||||
|
||||
internal static bool IsDistributedAuthority => NetworkManager.IsDistributedAuthority;
|
||||
|
||||
/// <summary>
|
||||
/// The collection item type tells the CMB server how to read the bytes of each item in the collection
|
||||
/// </summary>
|
||||
/// DANGO-EXP TODO: Determine if this is distributed authority only and impacts of this in client-server
|
||||
internal static CollectionItemType Type = CollectionItemType.Unknown;
|
||||
|
||||
/// <summary>
|
||||
/// A callback to check if two values are equal.
|
||||
/// </summary>
|
||||
@@ -59,7 +53,20 @@ namespace Unity.Netcode
|
||||
/// <param name="value"></param>
|
||||
public static void Write(FastBufferWriter writer, ref T value)
|
||||
{
|
||||
Serializer.Write(writer, ref value);
|
||||
if (IsDistributedAuthority)
|
||||
{
|
||||
#if DEVELOPMENT_BUILD || UNITY_EDITOR
|
||||
if (!NetworkManager.DisableNotOptimizedSerializedType && !Serializer.IsDistributedAuthorityOptimized)
|
||||
{
|
||||
NetworkManager.LogSerializedTypeNotOptimized<T>();
|
||||
}
|
||||
#endif
|
||||
Serializer.WriteDistributedAuthority(writer, ref value);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serializer.Write(writer, ref value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -84,7 +91,14 @@ namespace Unity.Netcode
|
||||
/// <param name="value"></param>
|
||||
public static void Read(FastBufferReader reader, ref T value)
|
||||
{
|
||||
Serializer.Read(reader, ref value);
|
||||
if (IsDistributedAuthority)
|
||||
{
|
||||
Serializer.ReadDistributedAuthority(reader, ref value);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serializer.Read(reader, ref value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -106,7 +120,20 @@ namespace Unity.Netcode
|
||||
/// <param name="value"></param>
|
||||
public static void WriteDelta(FastBufferWriter writer, ref T value, ref T previousValue)
|
||||
{
|
||||
Serializer.WriteDelta(writer, ref value, ref previousValue);
|
||||
if (IsDistributedAuthority)
|
||||
{
|
||||
#if DEVELOPMENT_BUILD || UNITY_EDITOR
|
||||
if (!NetworkManager.DisableNotOptimizedSerializedType && !Serializer.IsDistributedAuthorityOptimized)
|
||||
{
|
||||
NetworkManager.LogSerializedTypeNotOptimized<T>();
|
||||
}
|
||||
#endif
|
||||
Serializer.WriteDeltaDistributedAuthority(writer, ref value, ref previousValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serializer.WriteDelta(writer, ref value, ref previousValue);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -131,7 +158,14 @@ namespace Unity.Netcode
|
||||
/// <param name="value"></param>
|
||||
public static void ReadDelta(FastBufferReader reader, ref T value)
|
||||
{
|
||||
Serializer.ReadDelta(reader, ref value);
|
||||
if (IsDistributedAuthority)
|
||||
{
|
||||
Serializer.ReadDeltaDistributedAuthority(reader, ref value);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serializer.ReadDelta(reader, ref value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -38,14 +38,6 @@ namespace Unity.Netcode
|
||||
NetworkVariableSerialization<long>.AreEqual = NetworkVariableEquality<long>.ValueEquals;
|
||||
NetworkVariableSerialization<ulong>.Serializer = new UlongSerializer();
|
||||
NetworkVariableSerialization<ulong>.AreEqual = NetworkVariableEquality<ulong>.ValueEquals;
|
||||
|
||||
// DANGO-EXP TODO: Determine if this is distributed authority only and impacts of this in client-server
|
||||
NetworkVariableSerialization<short>.Type = CollectionItemType.Short;
|
||||
NetworkVariableSerialization<ushort>.Type = CollectionItemType.UShort;
|
||||
NetworkVariableSerialization<int>.Type = CollectionItemType.Int;
|
||||
NetworkVariableSerialization<uint>.Type = CollectionItemType.UInt;
|
||||
NetworkVariableSerialization<long>.Type = CollectionItemType.Long;
|
||||
NetworkVariableSerialization<ulong>.Type = CollectionItemType.ULong;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -55,8 +47,6 @@ namespace Unity.Netcode
|
||||
public static void InitializeSerializer_UnmanagedByMemcpy<T>() where T : unmanaged
|
||||
{
|
||||
NetworkVariableSerialization<T>.Serializer = new UnmanagedTypeSerializer<T>();
|
||||
// DANGO-EXP TODO: Determine if this is distributed authority only and impacts of this in client-server
|
||||
NetworkVariableSerialization<T>.Type = CollectionItemType.Unmanaged;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -10,6 +10,21 @@ namespace Unity.Netcode
|
||||
/// </summary>
|
||||
internal class ShortSerializer : INetworkVariableSerializer<short>
|
||||
{
|
||||
public NetworkVariableType Type => NetworkVariableType.Short;
|
||||
public bool IsDistributedAuthorityOptimized => true;
|
||||
|
||||
public void WriteDistributedAuthority(FastBufferWriter writer, ref short value)
|
||||
{
|
||||
Write(writer, ref value);
|
||||
}
|
||||
|
||||
public void ReadDistributedAuthority(FastBufferReader reader, ref short value)
|
||||
{
|
||||
Read(reader, ref value);
|
||||
}
|
||||
public void WriteDeltaDistributedAuthority(FastBufferWriter writer, ref short value, ref short previousValue) => Write(writer, ref value);
|
||||
public void ReadDeltaDistributedAuthority(FastBufferReader reader, ref short value) => Read(reader, ref value);
|
||||
|
||||
public void Write(FastBufferWriter writer, ref short value)
|
||||
{
|
||||
BytePacker.WriteValueBitPacked(writer, value);
|
||||
@@ -46,6 +61,20 @@ namespace Unity.Netcode
|
||||
/// </summary>
|
||||
internal class UshortSerializer : INetworkVariableSerializer<ushort>
|
||||
{
|
||||
public NetworkVariableType Type => NetworkVariableType.UShort;
|
||||
public bool IsDistributedAuthorityOptimized => true;
|
||||
|
||||
public void WriteDistributedAuthority(FastBufferWriter writer, ref ushort value)
|
||||
{
|
||||
Write(writer, ref value);
|
||||
}
|
||||
|
||||
public void ReadDistributedAuthority(FastBufferReader reader, ref ushort value)
|
||||
{
|
||||
Read(reader, ref value);
|
||||
}
|
||||
public void WriteDeltaDistributedAuthority(FastBufferWriter writer, ref ushort value, ref ushort previousValue) => Write(writer, ref value);
|
||||
public void ReadDeltaDistributedAuthority(FastBufferReader reader, ref ushort value) => Read(reader, ref value);
|
||||
public void Write(FastBufferWriter writer, ref ushort value)
|
||||
{
|
||||
BytePacker.WriteValueBitPacked(writer, value);
|
||||
@@ -82,6 +111,20 @@ namespace Unity.Netcode
|
||||
/// </summary>
|
||||
internal class IntSerializer : INetworkVariableSerializer<int>
|
||||
{
|
||||
public NetworkVariableType Type => NetworkVariableType.Int;
|
||||
public bool IsDistributedAuthorityOptimized => true;
|
||||
|
||||
public void WriteDistributedAuthority(FastBufferWriter writer, ref int value)
|
||||
{
|
||||
Write(writer, ref value);
|
||||
}
|
||||
|
||||
public void ReadDistributedAuthority(FastBufferReader reader, ref int value)
|
||||
{
|
||||
Read(reader, ref value);
|
||||
}
|
||||
public void WriteDeltaDistributedAuthority(FastBufferWriter writer, ref int value, ref int previousValue) => Write(writer, ref value);
|
||||
public void ReadDeltaDistributedAuthority(FastBufferReader reader, ref int value) => Read(reader, ref value);
|
||||
public void Write(FastBufferWriter writer, ref int value)
|
||||
{
|
||||
BytePacker.WriteValueBitPacked(writer, value);
|
||||
@@ -118,6 +161,20 @@ namespace Unity.Netcode
|
||||
/// </summary>
|
||||
internal class UintSerializer : INetworkVariableSerializer<uint>
|
||||
{
|
||||
public NetworkVariableType Type => NetworkVariableType.UInt;
|
||||
public bool IsDistributedAuthorityOptimized => true;
|
||||
|
||||
public void WriteDistributedAuthority(FastBufferWriter writer, ref uint value)
|
||||
{
|
||||
Write(writer, ref value);
|
||||
}
|
||||
|
||||
public void ReadDistributedAuthority(FastBufferReader reader, ref uint value)
|
||||
{
|
||||
Read(reader, ref value);
|
||||
}
|
||||
public void WriteDeltaDistributedAuthority(FastBufferWriter writer, ref uint value, ref uint previousValue) => Write(writer, ref value);
|
||||
public void ReadDeltaDistributedAuthority(FastBufferReader reader, ref uint value) => Read(reader, ref value);
|
||||
public void Write(FastBufferWriter writer, ref uint value)
|
||||
{
|
||||
BytePacker.WriteValueBitPacked(writer, value);
|
||||
@@ -154,6 +211,20 @@ namespace Unity.Netcode
|
||||
/// </summary>
|
||||
internal class LongSerializer : INetworkVariableSerializer<long>
|
||||
{
|
||||
public NetworkVariableType Type => NetworkVariableType.Long;
|
||||
public bool IsDistributedAuthorityOptimized => true;
|
||||
|
||||
public void WriteDistributedAuthority(FastBufferWriter writer, ref long value)
|
||||
{
|
||||
Write(writer, ref value);
|
||||
}
|
||||
|
||||
public void ReadDistributedAuthority(FastBufferReader reader, ref long value)
|
||||
{
|
||||
Read(reader, ref value);
|
||||
}
|
||||
public void WriteDeltaDistributedAuthority(FastBufferWriter writer, ref long value, ref long previousValue) => Write(writer, ref value);
|
||||
public void ReadDeltaDistributedAuthority(FastBufferReader reader, ref long value) => Read(reader, ref value);
|
||||
public void Write(FastBufferWriter writer, ref long value)
|
||||
{
|
||||
BytePacker.WriteValueBitPacked(writer, value);
|
||||
@@ -190,6 +261,21 @@ namespace Unity.Netcode
|
||||
/// </summary>
|
||||
internal class UlongSerializer : INetworkVariableSerializer<ulong>
|
||||
{
|
||||
public NetworkVariableType Type => NetworkVariableType.ULong;
|
||||
public bool IsDistributedAuthorityOptimized => true;
|
||||
|
||||
public void WriteDistributedAuthority(FastBufferWriter writer, ref ulong value)
|
||||
{
|
||||
Write(writer, ref value);
|
||||
}
|
||||
|
||||
public void ReadDistributedAuthority(FastBufferReader reader, ref ulong value)
|
||||
{
|
||||
Read(reader, ref value);
|
||||
}
|
||||
public void WriteDeltaDistributedAuthority(FastBufferWriter writer, ref ulong value, ref ulong previousValue) => Write(writer, ref value);
|
||||
public void ReadDeltaDistributedAuthority(FastBufferReader reader, ref ulong value) => Read(reader, ref value);
|
||||
|
||||
public void Write(FastBufferWriter writer, ref ulong value)
|
||||
{
|
||||
BytePacker.WriteValueBitPacked(writer, value);
|
||||
@@ -231,6 +317,21 @@ namespace Unity.Netcode
|
||||
/// <typeparam name="T"></typeparam>
|
||||
internal class UnmanagedTypeSerializer<T> : INetworkVariableSerializer<T> where T : unmanaged
|
||||
{
|
||||
public NetworkVariableType Type => NetworkVariableType.Unmanaged;
|
||||
public bool IsDistributedAuthorityOptimized => false;
|
||||
|
||||
public void WriteDistributedAuthority(FastBufferWriter writer, ref T value)
|
||||
{
|
||||
Write(writer, ref value);
|
||||
}
|
||||
|
||||
public void ReadDistributedAuthority(FastBufferReader reader, ref T value)
|
||||
{
|
||||
Read(reader, ref value);
|
||||
}
|
||||
public void WriteDeltaDistributedAuthority(FastBufferWriter writer, ref T value, ref T previousValue) => Write(writer, ref value);
|
||||
public void ReadDeltaDistributedAuthority(FastBufferReader reader, ref T value) => Read(reader, ref value);
|
||||
|
||||
public void Write(FastBufferWriter writer, ref T value)
|
||||
{
|
||||
writer.WriteUnmanagedSafe(value);
|
||||
@@ -264,6 +365,20 @@ namespace Unity.Netcode
|
||||
|
||||
internal class ListSerializer<T> : INetworkVariableSerializer<List<T>>
|
||||
{
|
||||
public NetworkVariableType Type => NetworkVariableType.Value;
|
||||
public bool IsDistributedAuthorityOptimized => false;
|
||||
|
||||
public void WriteDistributedAuthority(FastBufferWriter writer, ref List<T> value)
|
||||
{
|
||||
Write(writer, ref value);
|
||||
}
|
||||
|
||||
public void ReadDistributedAuthority(FastBufferReader reader, ref List<T> value)
|
||||
{
|
||||
Read(reader, ref value);
|
||||
}
|
||||
public void WriteDeltaDistributedAuthority(FastBufferWriter writer, ref List<T> value, ref List<T> previousValue) => Write(writer, ref value);
|
||||
public void ReadDeltaDistributedAuthority(FastBufferReader reader, ref List<T> value) => Read(reader, ref value);
|
||||
public void Write(FastBufferWriter writer, ref List<T> value)
|
||||
{
|
||||
var isNull = value == null;
|
||||
@@ -350,6 +465,20 @@ namespace Unity.Netcode
|
||||
|
||||
internal class HashSetSerializer<T> : INetworkVariableSerializer<HashSet<T>> where T : IEquatable<T>
|
||||
{
|
||||
public NetworkVariableType Type => NetworkVariableType.Value;
|
||||
public bool IsDistributedAuthorityOptimized => false;
|
||||
|
||||
public void WriteDistributedAuthority(FastBufferWriter writer, ref HashSet<T> value)
|
||||
{
|
||||
Write(writer, ref value);
|
||||
}
|
||||
|
||||
public void ReadDistributedAuthority(FastBufferReader reader, ref HashSet<T> value)
|
||||
{
|
||||
Read(reader, ref value);
|
||||
}
|
||||
public void WriteDeltaDistributedAuthority(FastBufferWriter writer, ref HashSet<T> value, ref HashSet<T> previousValue) => Write(writer, ref value);
|
||||
public void ReadDeltaDistributedAuthority(FastBufferReader reader, ref HashSet<T> value) => Read(reader, ref value);
|
||||
public void Write(FastBufferWriter writer, ref HashSet<T> value)
|
||||
{
|
||||
var isNull = value == null;
|
||||
@@ -428,6 +557,20 @@ namespace Unity.Netcode
|
||||
internal class DictionarySerializer<TKey, TVal> : INetworkVariableSerializer<Dictionary<TKey, TVal>>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
public NetworkVariableType Type => NetworkVariableType.Value;
|
||||
public bool IsDistributedAuthorityOptimized => false;
|
||||
|
||||
public void WriteDistributedAuthority(FastBufferWriter writer, ref Dictionary<TKey, TVal> value)
|
||||
{
|
||||
Write(writer, ref value);
|
||||
}
|
||||
|
||||
public void ReadDistributedAuthority(FastBufferReader reader, ref Dictionary<TKey, TVal> value)
|
||||
{
|
||||
Read(reader, ref value);
|
||||
}
|
||||
public void WriteDeltaDistributedAuthority(FastBufferWriter writer, ref Dictionary<TKey, TVal> value, ref Dictionary<TKey, TVal> previousValue) => Write(writer, ref value);
|
||||
public void ReadDeltaDistributedAuthority(FastBufferReader reader, ref Dictionary<TKey, TVal> value) => Read(reader, ref value);
|
||||
public void Write(FastBufferWriter writer, ref Dictionary<TKey, TVal> value)
|
||||
{
|
||||
var isNull = value == null;
|
||||
@@ -505,6 +648,20 @@ namespace Unity.Netcode
|
||||
|
||||
internal class UnmanagedArraySerializer<T> : INetworkVariableSerializer<NativeArray<T>> where T : unmanaged
|
||||
{
|
||||
public NetworkVariableType Type => NetworkVariableType.Value;
|
||||
public bool IsDistributedAuthorityOptimized => false;
|
||||
|
||||
public void WriteDistributedAuthority(FastBufferWriter writer, ref NativeArray<T> value)
|
||||
{
|
||||
Write(writer, ref value);
|
||||
}
|
||||
|
||||
public void ReadDistributedAuthority(FastBufferReader reader, ref NativeArray<T> value)
|
||||
{
|
||||
Read(reader, ref value);
|
||||
}
|
||||
public void WriteDeltaDistributedAuthority(FastBufferWriter writer, ref NativeArray<T> value, ref NativeArray<T> previousValue) => Write(writer, ref value);
|
||||
public void ReadDeltaDistributedAuthority(FastBufferReader reader, ref NativeArray<T> value) => Read(reader, ref value);
|
||||
public void Write(FastBufferWriter writer, ref NativeArray<T> value)
|
||||
{
|
||||
writer.WriteUnmanagedSafe(value);
|
||||
@@ -550,6 +707,20 @@ namespace Unity.Netcode
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
internal class UnmanagedListSerializer<T> : INetworkVariableSerializer<NativeList<T>> where T : unmanaged
|
||||
{
|
||||
public NetworkVariableType Type => NetworkVariableType.Value;
|
||||
public bool IsDistributedAuthorityOptimized => false;
|
||||
|
||||
public void WriteDistributedAuthority(FastBufferWriter writer, ref NativeList<T> value)
|
||||
{
|
||||
Write(writer, ref value);
|
||||
}
|
||||
|
||||
public void ReadDistributedAuthority(FastBufferReader reader, ref NativeList<T> value)
|
||||
{
|
||||
Read(reader, ref value);
|
||||
}
|
||||
public void WriteDeltaDistributedAuthority(FastBufferWriter writer, ref NativeList<T> value, ref NativeList<T> previousValue) => Write(writer, ref value);
|
||||
public void ReadDeltaDistributedAuthority(FastBufferReader reader, ref NativeList<T> value) => Read(reader, ref value);
|
||||
public void Write(FastBufferWriter writer, ref NativeList<T> value)
|
||||
{
|
||||
writer.WriteUnmanagedSafe(value);
|
||||
@@ -593,6 +764,21 @@ namespace Unity.Netcode
|
||||
|
||||
internal class NativeHashSetSerializer<T> : INetworkVariableSerializer<NativeHashSet<T>> where T : unmanaged, IEquatable<T>
|
||||
{
|
||||
public NetworkVariableType Type => NetworkVariableType.Value;
|
||||
public bool IsDistributedAuthorityOptimized => false;
|
||||
|
||||
public void WriteDistributedAuthority(FastBufferWriter writer, ref NativeHashSet<T> value)
|
||||
{
|
||||
Write(writer, ref value);
|
||||
}
|
||||
|
||||
public void ReadDistributedAuthority(FastBufferReader reader, ref NativeHashSet<T> value)
|
||||
{
|
||||
Read(reader, ref value);
|
||||
}
|
||||
public void WriteDeltaDistributedAuthority(FastBufferWriter writer, ref NativeHashSet<T> value, ref NativeHashSet<T> previousValue) => Write(writer, ref value);
|
||||
public void ReadDeltaDistributedAuthority(FastBufferReader reader, ref NativeHashSet<T> value) => Read(reader, ref value);
|
||||
|
||||
public void Write(FastBufferWriter writer, ref NativeHashSet<T> value)
|
||||
{
|
||||
writer.WriteValueSafe(value);
|
||||
@@ -638,6 +824,21 @@ namespace Unity.Netcode
|
||||
where TKey : unmanaged, IEquatable<TKey>
|
||||
where TVal : unmanaged
|
||||
{
|
||||
public NetworkVariableType Type => NetworkVariableType.Value;
|
||||
public bool IsDistributedAuthorityOptimized => false;
|
||||
|
||||
public void WriteDistributedAuthority(FastBufferWriter writer, ref NativeHashMap<TKey, TVal> value)
|
||||
{
|
||||
Write(writer, ref value);
|
||||
}
|
||||
|
||||
public void ReadDistributedAuthority(FastBufferReader reader, ref NativeHashMap<TKey, TVal> value)
|
||||
{
|
||||
Read(reader, ref value);
|
||||
}
|
||||
public void WriteDeltaDistributedAuthority(FastBufferWriter writer, ref NativeHashMap<TKey, TVal> value, ref NativeHashMap<TKey, TVal> previousValue) => Write(writer, ref value);
|
||||
public void ReadDeltaDistributedAuthority(FastBufferReader reader, ref NativeHashMap<TKey, TVal> value) => Read(reader, ref value);
|
||||
|
||||
public void Write(FastBufferWriter writer, ref NativeHashMap<TKey, TVal> value)
|
||||
{
|
||||
writer.WriteValueSafe(value);
|
||||
@@ -680,12 +881,25 @@ namespace Unity.Netcode
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Serializer for FixedStrings
|
||||
/// Serializer for FixedStrings
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
internal class FixedStringSerializer<T> : INetworkVariableSerializer<T> where T : unmanaged, INativeList<byte>, IUTF8Bytes
|
||||
{
|
||||
// The item type can only be bytes for fixedStrings, so the DA runtime doesn't need details on it
|
||||
public NetworkVariableType Type => NetworkVariableType.Value;
|
||||
public bool IsDistributedAuthorityOptimized => false;
|
||||
|
||||
public void WriteDistributedAuthority(FastBufferWriter writer, ref T value)
|
||||
{
|
||||
Write(writer, ref value);
|
||||
}
|
||||
|
||||
public void ReadDistributedAuthority(FastBufferReader reader, ref T value)
|
||||
{
|
||||
Read(reader, ref value);
|
||||
}
|
||||
public void WriteDeltaDistributedAuthority(FastBufferWriter writer, ref T value, ref T previousValue) => Write(writer, ref value);
|
||||
public void ReadDeltaDistributedAuthority(FastBufferReader reader, ref T value) => Read(reader, ref value);
|
||||
|
||||
public void Write(FastBufferWriter writer, ref T value)
|
||||
{
|
||||
@@ -731,7 +945,7 @@ namespace Unity.Netcode
|
||||
return;
|
||||
}
|
||||
|
||||
writer.WriteByte(0); // Flag that we're sending a delta
|
||||
writer.WriteByteSafe(0); // Flag that we're sending a delta
|
||||
BytePacker.WriteValuePacked(writer, value.Length);
|
||||
writer.WriteValueSafe(changes);
|
||||
var ptr = value.GetUnsafePtr();
|
||||
@@ -779,7 +993,7 @@ namespace Unity.Netcode
|
||||
{
|
||||
if (changes.IsSet(i))
|
||||
{
|
||||
reader.ReadByte(out ptr[i]);
|
||||
reader.ReadByteSafe(out ptr[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -802,6 +1016,20 @@ namespace Unity.Netcode
|
||||
/// <typeparam name="T"></typeparam>
|
||||
internal class FixedStringArraySerializer<T> : INetworkVariableSerializer<NativeArray<T>> where T : unmanaged, INativeList<byte>, IUTF8Bytes
|
||||
{
|
||||
public NetworkVariableType Type => NetworkVariableType.Value;
|
||||
public bool IsDistributedAuthorityOptimized => false;
|
||||
|
||||
public void WriteDistributedAuthority(FastBufferWriter writer, ref NativeArray<T> value)
|
||||
{
|
||||
Write(writer, ref value);
|
||||
}
|
||||
|
||||
public void ReadDistributedAuthority(FastBufferReader reader, ref NativeArray<T> value)
|
||||
{
|
||||
Read(reader, ref value);
|
||||
}
|
||||
public void WriteDeltaDistributedAuthority(FastBufferWriter writer, ref NativeArray<T> value, ref NativeArray<T> previousValue) => Write(writer, ref value);
|
||||
public void ReadDeltaDistributedAuthority(FastBufferReader reader, ref NativeArray<T> value) => Read(reader, ref value);
|
||||
public void Write(FastBufferWriter writer, ref NativeArray<T> value)
|
||||
{
|
||||
writer.WriteValueSafe(value);
|
||||
@@ -852,6 +1080,21 @@ namespace Unity.Netcode
|
||||
/// <typeparam name="T"></typeparam>
|
||||
internal class FixedStringListSerializer<T> : INetworkVariableSerializer<NativeList<T>> where T : unmanaged, INativeList<byte>, IUTF8Bytes
|
||||
{
|
||||
public NetworkVariableType Type => NetworkVariableType.Value;
|
||||
public bool IsDistributedAuthorityOptimized => false;
|
||||
|
||||
public void WriteDistributedAuthority(FastBufferWriter writer, ref NativeList<T> value)
|
||||
{
|
||||
Write(writer, ref value);
|
||||
}
|
||||
|
||||
public void ReadDistributedAuthority(FastBufferReader reader, ref NativeList<T> value)
|
||||
{
|
||||
Read(reader, ref value);
|
||||
}
|
||||
public void WriteDeltaDistributedAuthority(FastBufferWriter writer, ref NativeList<T> value, ref NativeList<T> previousValue) => Write(writer, ref value);
|
||||
public void ReadDeltaDistributedAuthority(FastBufferReader reader, ref NativeList<T> value) => Read(reader, ref value);
|
||||
|
||||
public void Write(FastBufferWriter writer, ref NativeList<T> value)
|
||||
{
|
||||
writer.WriteValueSafe(value);
|
||||
@@ -899,6 +1142,21 @@ namespace Unity.Netcode
|
||||
/// <typeparam name="T"></typeparam>
|
||||
internal class UnmanagedNetworkSerializableSerializer<T> : INetworkVariableSerializer<T> where T : unmanaged, INetworkSerializable
|
||||
{
|
||||
public NetworkVariableType Type => NetworkVariableType.Value;
|
||||
public bool IsDistributedAuthorityOptimized => false;
|
||||
|
||||
public void WriteDistributedAuthority(FastBufferWriter writer, ref T value)
|
||||
{
|
||||
Write(writer, ref value);
|
||||
}
|
||||
|
||||
public void ReadDistributedAuthority(FastBufferReader reader, ref T value)
|
||||
{
|
||||
Read(reader, ref value);
|
||||
}
|
||||
public void WriteDeltaDistributedAuthority(FastBufferWriter writer, ref T value, ref T previousValue) => Write(writer, ref value);
|
||||
public void ReadDeltaDistributedAuthority(FastBufferReader reader, ref T value) => Read(reader, ref value);
|
||||
|
||||
public void Write(FastBufferWriter writer, ref T value)
|
||||
{
|
||||
var bufferSerializer = new BufferSerializer<BufferSerializerWriter>(new BufferSerializerWriter(writer));
|
||||
@@ -951,6 +1209,20 @@ namespace Unity.Netcode
|
||||
/// <typeparam name="T"></typeparam>
|
||||
internal class UnmanagedNetworkSerializableArraySerializer<T> : INetworkVariableSerializer<NativeArray<T>> where T : unmanaged, INetworkSerializable
|
||||
{
|
||||
public NetworkVariableType Type => NetworkVariableType.Value;
|
||||
public bool IsDistributedAuthorityOptimized => false;
|
||||
|
||||
public void WriteDistributedAuthority(FastBufferWriter writer, ref NativeArray<T> value)
|
||||
{
|
||||
Write(writer, ref value);
|
||||
}
|
||||
|
||||
public void ReadDistributedAuthority(FastBufferReader reader, ref NativeArray<T> value)
|
||||
{
|
||||
Read(reader, ref value);
|
||||
}
|
||||
public void WriteDeltaDistributedAuthority(FastBufferWriter writer, ref NativeArray<T> value, ref NativeArray<T> previousValue) => Write(writer, ref value);
|
||||
public void ReadDeltaDistributedAuthority(FastBufferReader reader, ref NativeArray<T> value) => Read(reader, ref value);
|
||||
public void Write(FastBufferWriter writer, ref NativeArray<T> value)
|
||||
{
|
||||
writer.WriteNetworkSerializable(value);
|
||||
@@ -1001,6 +1273,21 @@ namespace Unity.Netcode
|
||||
/// <typeparam name="T"></typeparam>
|
||||
internal class UnmanagedNetworkSerializableListSerializer<T> : INetworkVariableSerializer<NativeList<T>> where T : unmanaged, INetworkSerializable
|
||||
{
|
||||
public NetworkVariableType Type => NetworkVariableType.Value;
|
||||
public bool IsDistributedAuthorityOptimized => false;
|
||||
|
||||
public void WriteDistributedAuthority(FastBufferWriter writer, ref NativeList<T> value)
|
||||
{
|
||||
Write(writer, ref value);
|
||||
}
|
||||
|
||||
public void ReadDistributedAuthority(FastBufferReader reader, ref NativeList<T> value)
|
||||
{
|
||||
Read(reader, ref value);
|
||||
}
|
||||
public void WriteDeltaDistributedAuthority(FastBufferWriter writer, ref NativeList<T> value, ref NativeList<T> previousValue) => Write(writer, ref value);
|
||||
public void ReadDeltaDistributedAuthority(FastBufferReader reader, ref NativeList<T> value) => Read(reader, ref value);
|
||||
|
||||
public void Write(FastBufferWriter writer, ref NativeList<T> value)
|
||||
{
|
||||
writer.WriteNetworkSerializable(value);
|
||||
@@ -1048,6 +1335,20 @@ namespace Unity.Netcode
|
||||
/// <typeparam name="T"></typeparam>
|
||||
internal class ManagedNetworkSerializableSerializer<T> : INetworkVariableSerializer<T> where T : class, INetworkSerializable, new()
|
||||
{
|
||||
public NetworkVariableType Type => NetworkVariableType.Value;
|
||||
public bool IsDistributedAuthorityOptimized => false;
|
||||
|
||||
public void WriteDistributedAuthority(FastBufferWriter writer, ref T value)
|
||||
{
|
||||
Write(writer, ref value);
|
||||
}
|
||||
|
||||
public void ReadDistributedAuthority(FastBufferReader reader, ref T value)
|
||||
{
|
||||
Read(reader, ref value);
|
||||
}
|
||||
public void WriteDeltaDistributedAuthority(FastBufferWriter writer, ref T value, ref T previousValue) => Write(writer, ref value);
|
||||
public void ReadDeltaDistributedAuthority(FastBufferReader reader, ref T value) => Read(reader, ref value);
|
||||
public void Write(FastBufferWriter writer, ref T value)
|
||||
{
|
||||
var bufferSerializer = new BufferSerializer<BufferSerializerWriter>(new BufferSerializerWriter(writer));
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Unity.Netcode
|
||||
{
|
||||
|
||||
internal static class SerializationTools
|
||||
{
|
||||
public delegate void WriteDelegate<T>(FastBufferWriter writer, ref T value);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void WriteWithSize<T>(WriteDelegate<T> writeMethod, FastBufferWriter writer, ref T value)
|
||||
{
|
||||
var writePos = writer.Position;
|
||||
// Note: This value can't be packed because we don't know how large it will be in advance
|
||||
// we reserve space for it, then write the data, then come back and fill in the space
|
||||
// to pack here, we'd have to write data to a temporary buffer and copy it in - which
|
||||
// isn't worth possibly saving one byte if and only if the data is less than 63 bytes long...
|
||||
// The way we do packing, any value > 63 in a ushort will use the full 2 bytes to represent.
|
||||
writer.WriteValueSafe((ushort)0);
|
||||
var startPos = writer.Position;
|
||||
writeMethod(writer, ref value);
|
||||
var size = writer.Position - startPos;
|
||||
writer.Seek(writePos);
|
||||
writer.WriteValueSafe((ushort)size);
|
||||
writer.Seek(startPos + size);
|
||||
}
|
||||
|
||||
public delegate void ReadDelegate<T>(FastBufferReader writer, ref T value);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void ReadWithSize<T>(ReadDelegate<T> readMethod, FastBufferReader reader, ref T value)
|
||||
{
|
||||
reader.ReadValueSafe(out ushort _);
|
||||
readMethod(reader, ref value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void WriteType(FastBufferWriter writer, NetworkVariableType type) => writer.WriteValueSafe(type);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void ReadType<T>(FastBufferReader reader, INetworkVariableSerializer<T> serializer)
|
||||
{
|
||||
reader.ReadValueSafe(out NetworkVariableType type);
|
||||
if (type != serializer.Type)
|
||||
{
|
||||
throw new SerializationException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 52a4ce368df54b0a8887c08f3402bcd3
|
||||
timeCreated: 1718300602
|
||||
Reference in New Issue
Block a user