com.unity.netcode.gameobjects@2.2.0
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.2.0] - 2024-12-12 ### Added - Added `NetworkObject.OwnershipStatus.SessionOwner` to allow Network Objects to be distributable and only owned by the Session Owner. This flag will override all other `OwnershipStatus` flags. (#3175) - Added `UnityTransport.GetEndpoint` method to provide a way to obtain `NetworkEndpoint` information of a connection via client identifier. (#3130) - Added `NetworkTransport.OnEarlyUpdate` and `NetworkTransport.OnPostLateUpdate` methods to provide more control over handling transport related events at the start and end of each frame. (#3113) ### Fixed - Fixed issue where the server, host, or session owner would not populate the in-scene place `NetworkObject` table if the scene was loaded prior to starting the `NetworkManager`. (#3177) - Fixed issue where the `NetworkObjectIdHash` value could be incorrect when entering play mode while still in prefab edit mode with pending changes and using MPPM. (#3162) - Fixed issue where a sever only `NetworkManager` instance would spawn the actual `NetworkPrefab`'s `GameObject` as opposed to creating an instance of it. (#3160) - Fixed issue where only the session owner (as opposed to all clients) would handle spawning prefab overrides properly when using a distributed authority network topology. (#3160) - Fixed issue where an exception was thrown when calling `NetworkManager.Shutdown` after calling `UnityTransport.Shutdown`. (#3118) - Fixed issue where `NetworkList` properties on in-scene placed `NetworkObject`s could cause small memory leaks when entering playmode. (#3147) - Fixed in-scene `NertworkObject` synchronization issue when loading a scene with currently connected clients connected to a session created by a `NetworkManager` started as a server (i.e. not as a host). (#3133) - Fixed issue where a `NetworkManager` started as a server would not add itself as an observer to in-scene placed `NetworkObject`s instantiated and spawned by a scene loading event. (#3133) - Fixed issue where spawning a player using `NetworkObject.InstantiateAndSpawn` or `NetworkSpawnManager.InstantiateAndSpawn` would not update the `NetworkSpawnManager.PlayerObjects` or assign the newly spawned player to the `NetworkClient.PlayerObject`. (#3122) - Fixed issue where queued UnitTransport (NetworkTransport) message batches were being sent on the next frame. They are now sent at the end of the frame during `PostLateUpdate`. (#3113) - Fixed issue where `NotOwnerRpcTarget` or `OwnerRpcTarget` were not using their replacements `NotAuthorityRpcTarget` and `AuthorityRpcTarget` which would invoke a warning. (#3111) - Fixed issue where client is removed as an observer from spawned objects when their player instance is despawned. (#3110) - Fixed issue where `NetworkAnimator` would statically allocate write buffer space for `Animator` parameters that could cause a write error if the number of parameters exceeded the space allocated. (#3108) ### Changed - In-scene placed `NetworkObject`s have been made distributable when balancing object distribution after a connection event. (#3175) - Optimised `NetworkVariable` and `NetworkTransform` related packets when in Distributed Authority mode. - The Debug Simulator section of the Unity Transport component was removed. This section was not functional anymore and users are now recommended to use the more featureful [Network Simulator](https://docs-multiplayer.unity3d.com/tools/current/tools-network-simulator/) tool from the Multiplayer Tools package instead. (#3121)
This commit is contained in:
@@ -14,9 +14,6 @@ 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}.");
|
||||
@@ -82,11 +79,6 @@ 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`
|
||||
|
||||
@@ -2,28 +2,8 @@ using Unity.Collections;
|
||||
|
||||
namespace Unity.Netcode
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface used by NetworkVariables to serialize them with additional information for the DA runtime
|
||||
/// </summary>
|
||||
///
|
||||
/// <typeparam name="T"></typeparam>
|
||||
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>
|
||||
internal interface INetworkVariableSerializer<T>
|
||||
{
|
||||
// Write has to be taken by ref here because of INetworkSerializable
|
||||
// Open Instance Delegates (pointers to methods without an instance attached to them)
|
||||
|
||||
@@ -14,8 +14,6 @@ namespace Unity.Netcode
|
||||
{
|
||||
internal static INetworkVariableSerializer<T> Serializer = new FallbackSerializer<T>();
|
||||
|
||||
internal static bool IsDistributedAuthority => NetworkManager.IsDistributedAuthority;
|
||||
|
||||
/// <summary>
|
||||
/// A callback to check if two values are equal.
|
||||
/// </summary>
|
||||
@@ -53,20 +51,7 @@ namespace Unity.Netcode
|
||||
/// <param name="value"></param>
|
||||
public static void Write(FastBufferWriter writer, ref T 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);
|
||||
}
|
||||
Serializer.Write(writer, ref value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -91,14 +76,7 @@ namespace Unity.Netcode
|
||||
/// <param name="value"></param>
|
||||
public static void Read(FastBufferReader reader, ref T value)
|
||||
{
|
||||
if (IsDistributedAuthority)
|
||||
{
|
||||
Serializer.ReadDistributedAuthority(reader, ref value);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serializer.Read(reader, ref value);
|
||||
}
|
||||
Serializer.Read(reader, ref value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -120,20 +98,7 @@ namespace Unity.Netcode
|
||||
/// <param name="value"></param>
|
||||
public static void WriteDelta(FastBufferWriter writer, ref T value, ref T 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);
|
||||
}
|
||||
Serializer.WriteDelta(writer, ref value, ref previousValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -158,14 +123,7 @@ namespace Unity.Netcode
|
||||
/// <param name="value"></param>
|
||||
public static void ReadDelta(FastBufferReader reader, ref T value)
|
||||
{
|
||||
if (IsDistributedAuthority)
|
||||
{
|
||||
Serializer.ReadDeltaDistributedAuthority(reader, ref value);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serializer.ReadDelta(reader, ref value);
|
||||
}
|
||||
Serializer.ReadDelta(reader, ref value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -10,21 +10,6 @@ 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);
|
||||
@@ -61,20 +46,6 @@ 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);
|
||||
@@ -111,20 +82,6 @@ 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);
|
||||
@@ -161,20 +118,6 @@ 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);
|
||||
@@ -211,20 +154,6 @@ 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);
|
||||
@@ -261,21 +190,6 @@ 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);
|
||||
@@ -317,21 +231,6 @@ 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);
|
||||
@@ -365,20 +264,6 @@ 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;
|
||||
@@ -468,20 +353,6 @@ 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;
|
||||
@@ -563,20 +434,6 @@ 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;
|
||||
@@ -659,20 +516,6 @@ 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);
|
||||
@@ -718,20 +561,6 @@ 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);
|
||||
@@ -775,21 +604,6 @@ 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);
|
||||
@@ -835,21 +649,6 @@ 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);
|
||||
@@ -897,21 +696,6 @@ namespace Unity.Netcode
|
||||
/// <typeparam name="T"></typeparam>
|
||||
internal class FixedStringSerializer<T> : INetworkVariableSerializer<T> where T : unmanaged, INativeList<byte>, IUTF8Bytes
|
||||
{
|
||||
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)
|
||||
{
|
||||
writer.WriteValueSafe(value);
|
||||
@@ -1019,20 +803,6 @@ 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);
|
||||
@@ -1083,21 +853,6 @@ 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);
|
||||
@@ -1145,21 +900,6 @@ 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));
|
||||
@@ -1212,20 +952,6 @@ 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);
|
||||
@@ -1276,21 +1002,6 @@ 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);
|
||||
@@ -1338,20 +1049,6 @@ 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));
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 52a4ce368df54b0a8887c08f3402bcd3
|
||||
timeCreated: 1718300602
|
||||
Reference in New Issue
Block a user