com.unity.netcode.gameobjects@1.5.1
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). ## [1.5.1] - 2023-06-07 ### Added - Added support for serializing `NativeArray<>` and `NativeList<>` in `FastBufferReader`/`FastBufferWriter`, `BufferSerializer`, `NetworkVariable`, and RPCs. (To use `NativeList<>`, add `UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT` to your Scripting Define Symbols in `Project Settings > Player`) (#2375) - The location of the automatically-created default network prefab list can now be configured (#2544) - Added: Message size limits (max single message and max fragmented message) can now be set using NetworkManager.MaximumTransmissionUnitSize and NetworkManager.MaximumFragmentedMessageSize for transports that don't work with the default values (#2530) - Added `NetworkObject.SpawnWithObservers` property (default is true) that when set to false will spawn a `NetworkObject` with no observers and will not be spawned on any client until `NetworkObject.NetworkShow` is invoked. (#2568) ### Fixed - Fixed: Fixed a null reference in codegen in some projects (#2581) - Fixed issue where the `OnClientDisconnected` client identifier was incorrect after a pending client connection was denied. (#2569) - Fixed warning "Runtime Network Prefabs was not empty at initialization time." being erroneously logged when no runtime network prefabs had been added (#2565) - Fixed issue where some temporary debug console logging was left in a merged PR. (#2562) - Fixed the "Generate Default Network Prefabs List" setting not loading correctly and always reverting to being checked. (#2545) - Fixed issue where users could not use NetworkSceneManager.VerifySceneBeforeLoading to exclude runtime generated scenes from client synchronization. (#2550) - Fixed missing value on `NetworkListEvent` for `EventType.RemoveAt` events. (#2542,#2543) - Fixed issue where parenting a NetworkTransform under a transform with a scale other than Vector3.one would result in incorrect values on non-authoritative instances. (#2538) - Fixed issue where a server would include scene migrated and then despawned NetworkObjects to a client that was being synchronized. (#2532) - Fixed the inspector throwing exceptions when attempting to render `NetworkVariable`s of enum types. (#2529) - Making a `NetworkVariable` with an `INetworkSerializable` type that doesn't meet the `new()` constraint will now create a compile-time error instead of an editor crash (#2528) - Fixed Multiplayer Tools package installation docs page link on the NetworkManager popup. (#2526) - Fixed an exception and error logging when two different objects are shown and hidden on the same frame (#2524) - Fixed a memory leak in `UnityTransport` that occurred if `StartClient` failed. (#2518) - Fixed issue where a client could throw an exception if abruptly disconnected from a network session with one or more spawned `NetworkObject`(s). (#2510) - Fixed issue where invalid endpoint addresses were not being detected and returning false from NGO UnityTransport. (#2496) - Fixed some errors that could occur if a connection is lost and the loss is detected when attempting to write to the socket. (#2495) ## Changed - Adding network prefabs before NetworkManager initialization is now supported. (#2565) - Connecting clients being synchronized now switch to the server's active scene before spawning and synchronizing NetworkObjects. (#2532) - Updated `UnityTransport` dependency on `com.unity.transport` to 1.3.4. (#2533) - Improved performance of NetworkBehaviour initialization by replacing reflection when initializing NetworkVariables with compile-time code generation, which should help reduce hitching during additive scene loads. (#2522)
This commit is contained in:
@@ -124,6 +124,25 @@ namespace Unity.Netcode
|
||||
/// <typeparam name="T">The type being serialized</typeparam>
|
||||
public void SerializeValue<T>(ref T[] value, FastBufferWriter.ForStructs unused = default) where T : unmanaged, INetworkSerializeByMemcpy => m_Implementation.SerializeValue(ref value);
|
||||
|
||||
/// <summary>
|
||||
/// Read or write a NativeArray of struct values implementing ISerializeByMemcpy
|
||||
/// </summary>
|
||||
/// <param name="value">The values to read/write</param>
|
||||
/// <param name="allocator">The allocator to use to construct the resulting NativeArray when reading</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution based on generic constraints</param>
|
||||
/// <typeparam name="T">The type being serialized</typeparam>
|
||||
public void SerializeValue<T>(ref NativeArray<T> value, Allocator allocator, FastBufferWriter.ForGeneric unused = default) where T : unmanaged => m_Implementation.SerializeValue(ref value, allocator);
|
||||
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
/// <summary>
|
||||
/// Read or write a NativeList of struct values implementing ISerializeByMemcpy
|
||||
/// </summary>
|
||||
/// <param name="value">The values to read/write</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution based on generic constraints</param>
|
||||
/// <typeparam name="T">The type being serialized</typeparam>
|
||||
public void SerializeValue<T>(ref NativeList<T> value, FastBufferWriter.ForGeneric unused = default) where T : unmanaged => m_Implementation.SerializeValue(ref value);
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Read or write a struct or class value implementing INetworkSerializable
|
||||
/// </summary>
|
||||
@@ -266,6 +285,7 @@ namespace Unity.Netcode
|
||||
// Those two are necessary to serialize FixedStrings efficiently
|
||||
// - otherwise we'd just be memcpy'ing the whole thing even if
|
||||
// most of it isn't used.
|
||||
|
||||
/// <summary>
|
||||
/// Read or write a FixedString value
|
||||
/// </summary>
|
||||
@@ -275,6 +295,27 @@ namespace Unity.Netcode
|
||||
public void SerializeValue<T>(ref T value, FastBufferWriter.ForFixedStrings unused = default)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes => m_Implementation.SerializeValue(ref value);
|
||||
|
||||
/// <summary>
|
||||
/// Read or write a NativeArray of FixedString values
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The network serializable type</typeparam>
|
||||
/// <param name="value">The values to read/write</param>
|
||||
/// <param name="allocator">The allocator to use to construct the resulting NativeArray when reading</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution of FixedStrings</param>
|
||||
public void SerializeValue<T>(ref NativeArray<T> value, Allocator allocator)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes => m_Implementation.SerializeValue(ref value, allocator);
|
||||
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
/// <summary>
|
||||
/// Read or write a NativeList of FixedString values
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The network serializable type</typeparam>
|
||||
/// <param name="value">The values to read/write</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution of FixedStrings</param>
|
||||
public void SerializeValue<T>(ref NativeList<T> value)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes => m_Implementation.SerializeValue(ref value);
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Read or write a NetworkSerializable value.
|
||||
/// SerializeValue() is the preferred method to do this - this is provided for backward compatibility only.
|
||||
@@ -381,6 +422,31 @@ namespace Unity.Netcode
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution of structs</param>
|
||||
public void SerializeValuePreChecked<T>(ref T[] value, FastBufferWriter.ForStructs unused = default) where T : unmanaged, INetworkSerializeByMemcpy => m_Implementation.SerializeValuePreChecked(ref value);
|
||||
|
||||
/// <summary>
|
||||
/// Serialize a NativeArray of structs, "pre-checked", which skips buffer checks.
|
||||
/// In debug and editor builds, a check is made to ensure you've called "PreCheck" before
|
||||
/// calling this. In release builds, calling this without calling "PreCheck" may read or write
|
||||
/// past the end of the buffer, which will cause memory corruption and undefined behavior.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The network serializable types in an array</typeparam>
|
||||
/// <param name="value">The values to read/write</param>
|
||||
/// <param name="allocator">The allocator to use to construct the resulting NativeArray when reading</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution of structs</param>
|
||||
public void SerializeValuePreChecked<T>(ref NativeArray<T> value, Allocator allocator, FastBufferWriter.ForGeneric unused = default) where T : unmanaged => m_Implementation.SerializeValuePreChecked(ref value, allocator);
|
||||
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
/// <summary>
|
||||
/// Serialize a NativeList of structs, "pre-checked", which skips buffer checks.
|
||||
/// In debug and editor builds, a check is made to ensure you've called "PreCheck" before
|
||||
/// calling this. In release builds, calling this without calling "PreCheck" may read or write
|
||||
/// past the end of the buffer, which will cause memory corruption and undefined behavior.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The network serializable types in an array</typeparam>
|
||||
/// <param name="value">The values to read/write</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution of structs</param>
|
||||
public void SerializeValuePreChecked<T>(ref NativeList<T> value, FastBufferWriter.ForGeneric unused = default) where T : unmanaged => m_Implementation.SerializeValuePreChecked(ref value);
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Serialize a Vector2, "pre-checked", which skips buffer checks.
|
||||
/// In debug and editor builds, a check is made to ensure you've called "PreCheck" before
|
||||
@@ -463,7 +529,7 @@ namespace Unity.Netcode
|
||||
public void SerializeValuePreChecked(ref Vector4 value) => m_Implementation.SerializeValuePreChecked(ref value);
|
||||
|
||||
/// <summary>
|
||||
/// Serialize a Vector4Array, "pre-checked", which skips buffer checks.
|
||||
/// Serialize a Vector4 array, "pre-checked", which skips buffer checks.
|
||||
/// In debug and editor builds, a check is made to ensure you've called "PreCheck" before
|
||||
/// calling this. In release builds, calling this without calling "PreCheck" may read or write
|
||||
/// past the end of the buffer, which will cause memory corruption and undefined behavior.
|
||||
|
||||
@@ -30,34 +30,56 @@ namespace Unity.Netcode
|
||||
public void SerializeValue(ref byte value) => m_Reader.ReadByteSafe(out value);
|
||||
public void SerializeValue<T>(ref T value, FastBufferWriter.ForPrimitives unused = default) where T : unmanaged, IComparable, IConvertible, IComparable<T>, IEquatable<T> => m_Reader.ReadValueSafe(out value);
|
||||
public void SerializeValue<T>(ref T[] value, FastBufferWriter.ForPrimitives unused = default) where T : unmanaged, IComparable, IConvertible, IComparable<T>, IEquatable<T> => m_Reader.ReadValueSafe(out value);
|
||||
|
||||
public void SerializeValue<T>(ref T value, FastBufferWriter.ForEnums unused = default) where T : unmanaged, Enum => m_Reader.ReadValueSafe(out value);
|
||||
public void SerializeValue<T>(ref T[] value, FastBufferWriter.ForEnums unused = default) where T : unmanaged, Enum => m_Reader.ReadValueSafe(out value);
|
||||
|
||||
public void SerializeValue<T>(ref T value, FastBufferWriter.ForStructs unused = default) where T : unmanaged, INetworkSerializeByMemcpy => m_Reader.ReadValueSafe(out value);
|
||||
public void SerializeValue<T>(ref T[] value, FastBufferWriter.ForStructs unused = default) where T : unmanaged, INetworkSerializeByMemcpy => m_Reader.ReadValueSafe(out value);
|
||||
public void SerializeValue<T>(ref NativeArray<T> value, Allocator allocator, FastBufferWriter.ForGeneric unused = default) where T : unmanaged => m_Reader.ReadValueSafe(out value, allocator);
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public void SerializeValue<T>(ref NativeList<T> value, FastBufferWriter.ForGeneric unused = default) where T : unmanaged => m_Reader.ReadValueSafeInPlace(ref value);
|
||||
#endif
|
||||
|
||||
public void SerializeValue<T>(ref T value, FastBufferWriter.ForNetworkSerializable unused = default) where T : INetworkSerializable, new() => m_Reader.ReadNetworkSerializableInPlace(ref value);
|
||||
public void SerializeValue<T>(ref T[] value, FastBufferWriter.ForNetworkSerializable unused = default) where T : INetworkSerializable, new() => m_Reader.ReadValue(out value);
|
||||
|
||||
public void SerializeValue<T>(ref T value, FastBufferWriter.ForFixedStrings unused = default)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes => m_Reader.ReadValueSafe(out value);
|
||||
|
||||
public void SerializeValue<T>(ref NativeArray<T> value, Allocator allocator) where T : unmanaged, INativeList<byte>, IUTF8Bytes => m_Reader.ReadValueSafe(out value, allocator);
|
||||
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public void SerializeValue<T>(ref NativeList<T> value) where T : unmanaged, INativeList<byte>, IUTF8Bytes => m_Reader.ReadValueSafeInPlace(ref value);
|
||||
#endif
|
||||
|
||||
public void SerializeValue(ref Vector2 value) => m_Reader.ReadValueSafe(out value);
|
||||
public void SerializeValue(ref Vector2[] value) => m_Reader.ReadValueSafe(out value);
|
||||
|
||||
public void SerializeValue(ref Vector3 value) => m_Reader.ReadValueSafe(out value);
|
||||
public void SerializeValue(ref Vector3[] value) => m_Reader.ReadValueSafe(out value);
|
||||
|
||||
public void SerializeValue(ref Vector2Int value) => m_Reader.ReadValueSafe(out value);
|
||||
public void SerializeValue(ref Vector2Int[] value) => m_Reader.ReadValueSafe(out value);
|
||||
|
||||
public void SerializeValue(ref Vector3Int value) => m_Reader.ReadValueSafe(out value);
|
||||
public void SerializeValue(ref Vector3Int[] value) => m_Reader.ReadValueSafe(out value);
|
||||
|
||||
public void SerializeValue(ref Vector4 value) => m_Reader.ReadValueSafe(out value);
|
||||
public void SerializeValue(ref Vector4[] value) => m_Reader.ReadValueSafe(out value);
|
||||
|
||||
public void SerializeValue(ref Quaternion value) => m_Reader.ReadValueSafe(out value);
|
||||
public void SerializeValue(ref Quaternion[] value) => m_Reader.ReadValueSafe(out value);
|
||||
|
||||
public void SerializeValue(ref Color value) => m_Reader.ReadValueSafe(out value);
|
||||
public void SerializeValue(ref Color[] value) => m_Reader.ReadValueSafe(out value);
|
||||
|
||||
public void SerializeValue(ref Color32 value) => m_Reader.ReadValueSafe(out value);
|
||||
public void SerializeValue(ref Color32[] value) => m_Reader.ReadValueSafe(out value);
|
||||
|
||||
public void SerializeValue(ref Ray value) => m_Reader.ReadValueSafe(out value);
|
||||
public void SerializeValue(ref Ray[] value) => m_Reader.ReadValueSafe(out value);
|
||||
|
||||
public void SerializeValue(ref Ray2D value) => m_Reader.ReadValueSafe(out value);
|
||||
public void SerializeValue(ref Ray2D[] value) => m_Reader.ReadValueSafe(out value);
|
||||
|
||||
@@ -72,30 +94,48 @@ namespace Unity.Netcode
|
||||
public void SerializeValuePreChecked(ref byte value) => m_Reader.ReadByte(out value);
|
||||
public void SerializeValuePreChecked<T>(ref T value, FastBufferWriter.ForPrimitives unused = default) where T : unmanaged, IComparable, IConvertible, IComparable<T>, IEquatable<T> => m_Reader.ReadValue(out value);
|
||||
public void SerializeValuePreChecked<T>(ref T[] value, FastBufferWriter.ForPrimitives unused = default) where T : unmanaged, IComparable, IConvertible, IComparable<T>, IEquatable<T> => m_Reader.ReadValue(out value);
|
||||
|
||||
public void SerializeValuePreChecked<T>(ref T value, FastBufferWriter.ForEnums unused = default) where T : unmanaged, Enum => m_Reader.ReadValue(out value);
|
||||
public void SerializeValuePreChecked<T>(ref T[] value, FastBufferWriter.ForEnums unused = default) where T : unmanaged, Enum => m_Reader.ReadValue(out value);
|
||||
|
||||
public void SerializeValuePreChecked<T>(ref T value, FastBufferWriter.ForStructs unused = default) where T : unmanaged, INetworkSerializeByMemcpy => m_Reader.ReadValue(out value);
|
||||
public void SerializeValuePreChecked<T>(ref T[] value, FastBufferWriter.ForStructs unused = default) where T : unmanaged, INetworkSerializeByMemcpy => m_Reader.ReadValue(out value);
|
||||
public void SerializeValuePreChecked<T>(ref NativeArray<T> value, Allocator allocator, FastBufferWriter.ForGeneric unused = default) where T : unmanaged => m_Reader.ReadValue(out value, allocator);
|
||||
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public void SerializeValuePreChecked<T>(ref NativeList<T> value, FastBufferWriter.ForGeneric unused = default) where T : unmanaged => m_Reader.ReadValueInPlace(ref value);
|
||||
#endif
|
||||
|
||||
public void SerializeValuePreChecked<T>(ref T value, FastBufferWriter.ForFixedStrings unused = default)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes => m_Reader.ReadValue(out value);
|
||||
|
||||
public void SerializeValuePreChecked(ref Vector2 value) => m_Reader.ReadValue(out value);
|
||||
public void SerializeValuePreChecked(ref Vector2[] value) => m_Reader.ReadValue(out value);
|
||||
|
||||
public void SerializeValuePreChecked(ref Vector3 value) => m_Reader.ReadValue(out value);
|
||||
public void SerializeValuePreChecked(ref Vector3[] value) => m_Reader.ReadValue(out value);
|
||||
|
||||
public void SerializeValuePreChecked(ref Vector2Int value) => m_Reader.ReadValue(out value);
|
||||
public void SerializeValuePreChecked(ref Vector2Int[] value) => m_Reader.ReadValue(out value);
|
||||
|
||||
public void SerializeValuePreChecked(ref Vector3Int value) => m_Reader.ReadValue(out value);
|
||||
public void SerializeValuePreChecked(ref Vector3Int[] value) => m_Reader.ReadValue(out value);
|
||||
|
||||
public void SerializeValuePreChecked(ref Vector4 value) => m_Reader.ReadValue(out value);
|
||||
public void SerializeValuePreChecked(ref Vector4[] value) => m_Reader.ReadValue(out value);
|
||||
|
||||
public void SerializeValuePreChecked(ref Quaternion value) => m_Reader.ReadValue(out value);
|
||||
public void SerializeValuePreChecked(ref Quaternion[] value) => m_Reader.ReadValue(out value);
|
||||
|
||||
public void SerializeValuePreChecked(ref Color value) => m_Reader.ReadValue(out value);
|
||||
public void SerializeValuePreChecked(ref Color[] value) => m_Reader.ReadValue(out value);
|
||||
|
||||
public void SerializeValuePreChecked(ref Color32 value) => m_Reader.ReadValue(out value);
|
||||
public void SerializeValuePreChecked(ref Color32[] value) => m_Reader.ReadValue(out value);
|
||||
|
||||
public void SerializeValuePreChecked(ref Ray value) => m_Reader.ReadValue(out value);
|
||||
public void SerializeValuePreChecked(ref Ray[] value) => m_Reader.ReadValue(out value);
|
||||
|
||||
public void SerializeValuePreChecked(ref Ray2D value) => m_Reader.ReadValue(out value);
|
||||
public void SerializeValuePreChecked(ref Ray2D[] value) => m_Reader.ReadValue(out value);
|
||||
}
|
||||
|
||||
@@ -30,33 +30,55 @@ namespace Unity.Netcode
|
||||
public void SerializeValue(ref byte value) => m_Writer.WriteByteSafe(value);
|
||||
public void SerializeValue<T>(ref T value, FastBufferWriter.ForPrimitives unused = default) where T : unmanaged, IComparable, IConvertible, IComparable<T>, IEquatable<T> => m_Writer.WriteValueSafe(value);
|
||||
public void SerializeValue<T>(ref T[] value, FastBufferWriter.ForPrimitives unused = default) where T : unmanaged, IComparable, IConvertible, IComparable<T>, IEquatable<T> => m_Writer.WriteValueSafe(value);
|
||||
|
||||
public void SerializeValue<T>(ref T value, FastBufferWriter.ForEnums unused = default) where T : unmanaged, Enum => m_Writer.WriteValueSafe(value);
|
||||
public void SerializeValue<T>(ref T[] value, FastBufferWriter.ForEnums unused = default) where T : unmanaged, Enum => m_Writer.WriteValueSafe(value);
|
||||
|
||||
public void SerializeValue<T>(ref T value, FastBufferWriter.ForStructs unused = default) where T : unmanaged, INetworkSerializeByMemcpy => m_Writer.WriteValueSafe(value);
|
||||
public void SerializeValue<T>(ref T[] value, FastBufferWriter.ForStructs unused = default) where T : unmanaged, INetworkSerializeByMemcpy => m_Writer.WriteValueSafe(value);
|
||||
public void SerializeValue<T>(ref NativeArray<T> value, Allocator allocator, FastBufferWriter.ForGeneric unused = default) where T : unmanaged => m_Writer.WriteValueSafe(value);
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public void SerializeValue<T>(ref NativeList<T> value, FastBufferWriter.ForGeneric unused = default) where T : unmanaged => m_Writer.WriteValueSafe(value);
|
||||
#endif
|
||||
|
||||
public void SerializeValue<T>(ref T value, FastBufferWriter.ForNetworkSerializable unused = default) where T : INetworkSerializable, new() => m_Writer.WriteValue(value);
|
||||
public void SerializeValue<T>(ref T[] value, FastBufferWriter.ForNetworkSerializable unused = default) where T : INetworkSerializable, new() => m_Writer.WriteValue(value);
|
||||
|
||||
public void SerializeValue<T>(ref T value, FastBufferWriter.ForFixedStrings unused = default)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes => m_Writer.WriteValueSafe(value);
|
||||
public void SerializeValue<T>(ref NativeArray<T> value, Allocator allocator) where T : unmanaged, INativeList<byte>, IUTF8Bytes => m_Writer.WriteValueSafe(value);
|
||||
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public void SerializeValue<T>(ref NativeList<T> value) where T : unmanaged, INativeList<byte>, IUTF8Bytes => m_Writer.WriteValueSafe(value);
|
||||
#endif
|
||||
|
||||
public void SerializeValue(ref Vector2 value) => m_Writer.WriteValueSafe(value);
|
||||
public void SerializeValue(ref Vector2[] value) => m_Writer.WriteValueSafe(value);
|
||||
|
||||
public void SerializeValue(ref Vector3 value) => m_Writer.WriteValueSafe(value);
|
||||
public void SerializeValue(ref Vector3[] value) => m_Writer.WriteValueSafe(value);
|
||||
|
||||
public void SerializeValue(ref Vector2Int value) => m_Writer.WriteValueSafe(value);
|
||||
public void SerializeValue(ref Vector2Int[] value) => m_Writer.WriteValueSafe(value);
|
||||
|
||||
public void SerializeValue(ref Vector3Int value) => m_Writer.WriteValueSafe(value);
|
||||
public void SerializeValue(ref Vector3Int[] value) => m_Writer.WriteValueSafe(value);
|
||||
|
||||
public void SerializeValue(ref Vector4 value) => m_Writer.WriteValueSafe(value);
|
||||
public void SerializeValue(ref Vector4[] value) => m_Writer.WriteValueSafe(value);
|
||||
|
||||
public void SerializeValue(ref Quaternion value) => m_Writer.WriteValueSafe(value);
|
||||
public void SerializeValue(ref Quaternion[] value) => m_Writer.WriteValueSafe(value);
|
||||
|
||||
public void SerializeValue(ref Color value) => m_Writer.WriteValueSafe(value);
|
||||
public void SerializeValue(ref Color[] value) => m_Writer.WriteValueSafe(value);
|
||||
|
||||
public void SerializeValue(ref Color32 value) => m_Writer.WriteValueSafe(value);
|
||||
public void SerializeValue(ref Color32[] value) => m_Writer.WriteValueSafe(value);
|
||||
|
||||
public void SerializeValue(ref Ray value) => m_Writer.WriteValueSafe(value);
|
||||
public void SerializeValue(ref Ray[] value) => m_Writer.WriteValueSafe(value);
|
||||
|
||||
public void SerializeValue(ref Ray2D value) => m_Writer.WriteValueSafe(value);
|
||||
public void SerializeValue(ref Ray2D[] value) => m_Writer.WriteValueSafe(value);
|
||||
|
||||
@@ -77,29 +99,44 @@ namespace Unity.Netcode
|
||||
|
||||
public void SerializeValuePreChecked<T>(ref T value, FastBufferWriter.ForEnums unused = default) where T : unmanaged, Enum => m_Writer.WriteValue(value);
|
||||
public void SerializeValuePreChecked<T>(ref T[] value, FastBufferWriter.ForEnums unused = default) where T : unmanaged, Enum => m_Writer.WriteValue(value);
|
||||
|
||||
public void SerializeValuePreChecked<T>(ref T value, FastBufferWriter.ForStructs unused = default) where T : unmanaged, INetworkSerializeByMemcpy => m_Writer.WriteValue(value);
|
||||
public void SerializeValuePreChecked<T>(ref T[] value, FastBufferWriter.ForStructs unused = default) where T : unmanaged, INetworkSerializeByMemcpy => m_Writer.WriteValue(value);
|
||||
public void SerializeValuePreChecked<T>(ref NativeArray<T> value, Allocator allocator, FastBufferWriter.ForGeneric unused = default) where T : unmanaged => m_Writer.WriteValue(value);
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
public void SerializeValuePreChecked<T>(ref NativeList<T> value, FastBufferWriter.ForGeneric unused = default) where T : unmanaged => m_Writer.WriteValue(value);
|
||||
#endif
|
||||
|
||||
public void SerializeValuePreChecked<T>(ref T value, FastBufferWriter.ForFixedStrings unused = default)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes => m_Writer.WriteValue(value);
|
||||
|
||||
public void SerializeValuePreChecked(ref Vector2 value) => m_Writer.WriteValue(value);
|
||||
public void SerializeValuePreChecked(ref Vector2[] value) => m_Writer.WriteValue(value);
|
||||
|
||||
public void SerializeValuePreChecked(ref Vector3 value) => m_Writer.WriteValue(value);
|
||||
public void SerializeValuePreChecked(ref Vector3[] value) => m_Writer.WriteValue(value);
|
||||
|
||||
public void SerializeValuePreChecked(ref Vector2Int value) => m_Writer.WriteValue(value);
|
||||
public void SerializeValuePreChecked(ref Vector2Int[] value) => m_Writer.WriteValue(value);
|
||||
|
||||
public void SerializeValuePreChecked(ref Vector3Int value) => m_Writer.WriteValue(value);
|
||||
public void SerializeValuePreChecked(ref Vector3Int[] value) => m_Writer.WriteValue(value);
|
||||
|
||||
public void SerializeValuePreChecked(ref Vector4 value) => m_Writer.WriteValue(value);
|
||||
public void SerializeValuePreChecked(ref Vector4[] value) => m_Writer.WriteValue(value);
|
||||
|
||||
public void SerializeValuePreChecked(ref Quaternion value) => m_Writer.WriteValue(value);
|
||||
public void SerializeValuePreChecked(ref Quaternion[] value) => m_Writer.WriteValue(value);
|
||||
|
||||
public void SerializeValuePreChecked(ref Color value) => m_Writer.WriteValue(value);
|
||||
public void SerializeValuePreChecked(ref Color[] value) => m_Writer.WriteValue(value);
|
||||
|
||||
public void SerializeValuePreChecked(ref Color32 value) => m_Writer.WriteValue(value);
|
||||
public void SerializeValuePreChecked(ref Color32[] value) => m_Writer.WriteValue(value);
|
||||
|
||||
public void SerializeValuePreChecked(ref Ray value) => m_Writer.WriteValue(value);
|
||||
public void SerializeValuePreChecked(ref Ray[] value) => m_Writer.WriteValue(value);
|
||||
|
||||
public void SerializeValuePreChecked(ref Ray2D value) => m_Writer.WriteValue(value);
|
||||
public void SerializeValuePreChecked(ref Ray2D[] value) => m_Writer.WriteValue(value);
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace Unity.Netcode
|
||||
|
||||
private static unsafe ReaderHandle* CreateHandle(byte* buffer, int length, int offset, Allocator copyAllocator, Allocator internalAllocator)
|
||||
{
|
||||
ReaderHandle* readerHandle = null;
|
||||
ReaderHandle* readerHandle;
|
||||
if (copyAllocator == Allocator.None)
|
||||
{
|
||||
readerHandle = (ReaderHandle*)UnsafeUtility.Malloc(sizeof(ReaderHandle), UnsafeUtility.AlignOf<byte>(), internalAllocator);
|
||||
@@ -461,6 +461,42 @@ namespace Unity.Netcode
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a NativeArray of INetworkSerializables
|
||||
/// </summary>
|
||||
/// <param name="value">INetworkSerializable instance</param>
|
||||
/// <param name="allocator">The allocator to use to construct the resulting NativeArray</param>
|
||||
/// <typeparam name="T">the array to read the values of type `T` into</typeparam>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public void ReadNetworkSerializable<T>(out NativeArray<T> value, Allocator allocator) where T : unmanaged, INetworkSerializable
|
||||
{
|
||||
ReadValueSafe(out int size);
|
||||
value = new NativeArray<T>(size, allocator);
|
||||
for (var i = 0; i < size; ++i)
|
||||
{
|
||||
ReadNetworkSerializable(out T item);
|
||||
value[i] = item;
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
/// <summary>
|
||||
/// Read a NativeList of INetworkSerializables
|
||||
/// </summary>
|
||||
/// <param name="value">INetworkSerializable instance</param>
|
||||
/// <typeparam name="T">the array to read the values of type `T` into</typeparam>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public void ReadNetworkSerializableInPlace<T>(ref NativeList<T> value) where T : unmanaged, INetworkSerializable
|
||||
{
|
||||
ReadValueSafe(out int size);
|
||||
value.Resize(size, NativeArrayOptions.UninitializedMemory);
|
||||
for (var i = 0; i < size; ++i)
|
||||
{
|
||||
ReadNetworkSerializable(out value.ElementAt(i));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Read an INetworkSerializable in-place, without constructing a new one
|
||||
/// Note that this will NOT check for null before calling NetworkSerialize
|
||||
@@ -757,6 +793,44 @@ namespace Unity.Netcode
|
||||
ReadBytesSafe(bytes, sizeInBytes);
|
||||
}
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal unsafe void ReadUnmanaged<T>(out NativeArray<T> value, Allocator allocator) where T : unmanaged
|
||||
{
|
||||
ReadUnmanaged(out int sizeInTs);
|
||||
int sizeInBytes = sizeInTs * sizeof(T);
|
||||
value = new NativeArray<T>(sizeInTs, allocator);
|
||||
byte* bytes = (byte*)value.GetUnsafePtr();
|
||||
ReadBytes(bytes, sizeInBytes);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal unsafe void ReadUnmanagedSafe<T>(out NativeArray<T> value, Allocator allocator) where T : unmanaged
|
||||
{
|
||||
ReadUnmanagedSafe(out int sizeInTs);
|
||||
int sizeInBytes = sizeInTs * sizeof(T);
|
||||
value = new NativeArray<T>(sizeInTs, allocator);
|
||||
byte* bytes = (byte*)value.GetUnsafePtr();
|
||||
ReadBytesSafe(bytes, sizeInBytes);
|
||||
}
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal unsafe void ReadUnmanagedInPlace<T>(ref NativeList<T> value) where T : unmanaged
|
||||
{
|
||||
ReadUnmanaged(out int sizeInTs);
|
||||
int sizeInBytes = sizeInTs * sizeof(T);
|
||||
value.Resize(sizeInTs, NativeArrayOptions.UninitializedMemory);
|
||||
byte* bytes = (byte*)value.GetUnsafePtr();
|
||||
ReadBytes(bytes, sizeInBytes);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal unsafe void ReadUnmanagedSafeInPlace<T>(ref NativeList<T> value) where T : unmanaged
|
||||
{
|
||||
ReadUnmanagedSafe(out int sizeInTs);
|
||||
int sizeInBytes = sizeInTs * sizeof(T);
|
||||
value.Resize(sizeInTs, NativeArrayOptions.UninitializedMemory);
|
||||
byte* bytes = (byte*)value.GetUnsafePtr();
|
||||
ReadBytesSafe(bytes, sizeInBytes);
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Read a NetworkSerializable value
|
||||
@@ -800,6 +874,19 @@ namespace Unity.Netcode
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void ReadValueSafe<T>(out T[] value, FastBufferWriter.ForNetworkSerializable unused = default) where T : INetworkSerializable, new() => ReadNetworkSerializable(out value);
|
||||
|
||||
/// <summary>
|
||||
/// Read a NetworkSerializable NativeArray
|
||||
///
|
||||
/// "Safe" version - automatically performs bounds checking. Less efficient than bounds checking
|
||||
/// for multiple reads at once by calling TryBeginRead.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type being serialized</typeparam>
|
||||
/// <param name="value">The values to read</param>
|
||||
/// <param name="allocator">The allocator to use to construct the resulting NativeArray</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution based on generic constraints</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void ReadValueSafe<T>(out NativeArray<T> value, Allocator allocator, FastBufferWriter.ForNetworkSerializable unused = default) where T : unmanaged, INetworkSerializable => ReadNetworkSerializable(out value, allocator);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Read a struct
|
||||
@@ -819,6 +906,72 @@ namespace Unity.Netcode
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void ReadValue<T>(out T[] value, FastBufferWriter.ForStructs unused = default) where T : unmanaged, INetworkSerializeByMemcpy => ReadUnmanaged(out value);
|
||||
|
||||
/// <summary>
|
||||
/// Read a struct NativeArray
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type being serialized</typeparam>
|
||||
/// <param name="value">The values to read</param>
|
||||
/// <param name="allocator">The allocator to use to construct the resulting NativeArray</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution based on generic constraints</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void ReadValue<T>(out NativeArray<T> value, Allocator allocator, FastBufferWriter.ForGeneric unused = default) where T : unmanaged
|
||||
{
|
||||
if (typeof(INetworkSerializable).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
// This calls WriteNetworkSerializable in a way that doesn't require
|
||||
// any boxing.
|
||||
NetworkVariableSerialization<NativeArray<T>>.Serializer.ReadWithAllocator(this, out value, allocator);
|
||||
}
|
||||
else
|
||||
{
|
||||
ReadUnmanaged(out value, allocator);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a struct NativeArray using a Temp allocator. Equivalent to ReadValue(out value, Allocator.Temp)
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type being serialized</typeparam>
|
||||
/// <param name="value">The values to read</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution based on generic constraints</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void ReadValueTemp<T>(out NativeArray<T> value, FastBufferWriter.ForGeneric unused = default) where T : unmanaged
|
||||
{
|
||||
if (typeof(INetworkSerializable).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
// This calls WriteNetworkSerializable in a way that doesn't require
|
||||
// any boxing.
|
||||
NetworkVariableSerialization<NativeArray<T>>.Serializer.ReadWithAllocator(this, out value, Allocator.Temp);
|
||||
}
|
||||
else
|
||||
{
|
||||
ReadUnmanaged(out value, Allocator.Temp);
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
/// <summary>
|
||||
/// Read a struct NativeList
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type being serialized</typeparam>
|
||||
/// <param name="value">The values to read</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution based on generic constraints</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void ReadValueInPlace<T>(ref NativeList<T> value, FastBufferWriter.ForGeneric unused = default) where T : unmanaged
|
||||
{
|
||||
if (typeof(INetworkSerializable).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
// This calls WriteNetworkSerializable in a way that doesn't require
|
||||
// any boxing.
|
||||
NetworkVariableSerialization<NativeList<T>>.Serializer.Read(this, ref value);
|
||||
}
|
||||
else
|
||||
{
|
||||
ReadUnmanagedInPlace(ref value);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Read a struct
|
||||
///
|
||||
@@ -843,6 +996,81 @@ namespace Unity.Netcode
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void ReadValueSafe<T>(out T[] value, FastBufferWriter.ForStructs unused = default) where T : unmanaged, INetworkSerializeByMemcpy => ReadUnmanagedSafe(out value);
|
||||
|
||||
/// <summary>
|
||||
/// Read a struct NativeArray
|
||||
///
|
||||
/// "Safe" version - automatically performs bounds checking. Less efficient than bounds checking
|
||||
/// for multiple reads at once by calling TryBeginRead.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type being serialized</typeparam>
|
||||
/// <param name="value">The values to read</param>
|
||||
/// <param name="allocator">The allocator to use to construct the resulting NativeArray</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution based on generic constraints</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void ReadValueSafe<T>(out NativeArray<T> value, Allocator allocator, FastBufferWriter.ForGeneric unused = default) where T : unmanaged
|
||||
{
|
||||
if (typeof(INetworkSerializable).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
// This calls WriteNetworkSerializable in a way that doesn't require
|
||||
// any boxing.
|
||||
NetworkVariableSerialization<NativeArray<T>>.Serializer.ReadWithAllocator(this, out value, allocator);
|
||||
}
|
||||
else
|
||||
{
|
||||
ReadUnmanagedSafe(out value, allocator);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a struct NativeArray using a Temp allocator. Equivalent to ReadValueSafe(out value, Allocator.Temp)
|
||||
///
|
||||
/// "Safe" version - automatically performs bounds checking. Less efficient than bounds checking
|
||||
/// for multiple reads at once by calling TryBeginRead.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type being serialized</typeparam>
|
||||
/// <param name="value">The values to read</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution based on generic constraints</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void ReadValueSafeTemp<T>(out NativeArray<T> value, FastBufferWriter.ForGeneric unused = default) where T : unmanaged
|
||||
{
|
||||
if (typeof(INetworkSerializable).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
// This calls WriteNetworkSerializable in a way that doesn't require
|
||||
// any boxing.
|
||||
NetworkVariableSerialization<NativeArray<T>>.Serializer.ReadWithAllocator(this, out value, Allocator.Temp);
|
||||
}
|
||||
else
|
||||
{
|
||||
ReadUnmanagedSafe(out value, Allocator.Temp);
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
/// <summary>
|
||||
/// Read a struct NativeList
|
||||
///
|
||||
/// "Safe" version - automatically performs bounds checking. Less efficient than bounds checking
|
||||
/// for multiple reads at once by calling TryBeginRead.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type being serialized</typeparam>
|
||||
/// <param name="value">The values to read</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution based on generic constraints</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void ReadValueSafeInPlace<T>(ref NativeList<T> value, FastBufferWriter.ForGeneric unused = default) where T : unmanaged
|
||||
{
|
||||
if (typeof(INetworkSerializable).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
// This calls WriteNetworkSerializable in a way that doesn't require
|
||||
// any boxing.
|
||||
NetworkVariableSerialization<NativeList<T>>.Serializer.Read(this, ref value);
|
||||
}
|
||||
else
|
||||
{
|
||||
ReadUnmanagedSafeInPlace(ref value);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Read a primitive value (int, bool, etc)
|
||||
/// Accepts any value that implements the given interfaces, but is not guaranteed to work correctly
|
||||
@@ -880,7 +1108,7 @@ namespace Unity.Netcode
|
||||
public void ReadValueSafe<T>(out T value, FastBufferWriter.ForPrimitives unused = default) where T : unmanaged, IComparable, IConvertible, IComparable<T>, IEquatable<T> => ReadUnmanagedSafe(out value);
|
||||
|
||||
/// <summary>
|
||||
/// Read a primitive value (int, bool, etc)
|
||||
/// Read a primitive value (int, bool, etc) array
|
||||
/// Accepts any value that implements the given interfaces, but is not guaranteed to work correctly
|
||||
/// on values that are not primitives.
|
||||
///
|
||||
@@ -936,6 +1164,7 @@ namespace Unity.Netcode
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void ReadValueSafe<T>(out T[] value, FastBufferWriter.ForEnums unused = default) where T : unmanaged, Enum => ReadUnmanagedSafe(out value);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Read a Vector2
|
||||
/// </summary>
|
||||
@@ -1346,5 +1575,94 @@ namespace Unity.Netcode
|
||||
value.Length = length;
|
||||
ReadBytesSafe(value.GetUnsafePtr(), length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a FixedString NativeArray.
|
||||
///
|
||||
/// "Safe" version - automatically performs bounds checking. Less efficient than bounds checking
|
||||
/// for multiple reads at once by calling TryBeginRead.
|
||||
/// </summary>
|
||||
/// <param name="value">the value to read</param>
|
||||
/// <param name="allocator">The allocator to use to construct the resulting NativeArray</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution based on generic constraints</param>
|
||||
/// <typeparam name="T">The type being serialized</typeparam>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void ReadValueSafe<T>(out NativeArray<T> value, Allocator allocator)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes
|
||||
{
|
||||
ReadUnmanagedSafe(out int length);
|
||||
value = new NativeArray<T>(length, allocator);
|
||||
var ptr = (T*)value.GetUnsafePtr();
|
||||
for (var i = 0; i < length; ++i)
|
||||
{
|
||||
ReadValueSafeInPlace(ref ptr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a FixedString NativeArray using a Temp allocator. Equivalent to ReadValueSafe(out value, Allocator.Temp)
|
||||
///
|
||||
/// "Safe" version - automatically performs bounds checking. Less efficient than bounds checking
|
||||
/// for multiple reads at once by calling TryBeginRead.
|
||||
/// </summary>
|
||||
/// <param name="value">the value to read</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution based on generic constraints</param>
|
||||
/// <typeparam name="T">The type being serialized</typeparam>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void ReadValueSafeTemp<T>(out NativeArray<T> value)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes
|
||||
{
|
||||
ReadUnmanagedSafe(out int length);
|
||||
value = new NativeArray<T>(length, Allocator.Temp);
|
||||
var ptr = (T*)value.GetUnsafePtr();
|
||||
for (var i = 0; i < length; ++i)
|
||||
{
|
||||
ReadValueSafeInPlace(ref ptr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a FixedString NativeArray using a Temp allocator. Equivalent to ReadValueSafe(out value, Allocator.Temp)
|
||||
///
|
||||
/// "Safe" version - automatically performs bounds checking. Less efficient than bounds checking
|
||||
/// for multiple reads at once by calling TryBeginRead.
|
||||
/// </summary>
|
||||
/// <param name="value">the value to read</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution based on generic constraints</param>
|
||||
/// <typeparam name="T">The type being serialized</typeparam>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void ReadValueSafe<T>(out T[] value, FastBufferWriter.ForFixedStrings unused = default)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes
|
||||
{
|
||||
ReadUnmanagedSafe(out int length);
|
||||
value = new T[length];
|
||||
for (var i = 0; i < length; ++i)
|
||||
{
|
||||
ReadValueSafeInPlace(ref value[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
/// <summary>
|
||||
/// Read a FixedString NativeList.
|
||||
///
|
||||
/// "Safe" version - automatically performs bounds checking. Less efficient than bounds checking
|
||||
/// for multiple reads at once by calling TryBeginRead.
|
||||
/// </summary>
|
||||
/// <param name="value">the value to read</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution based on generic constraints</param>
|
||||
/// <typeparam name="T">The type being serialized</typeparam>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void ReadValueSafeInPlace<T>(ref NativeList<T> value)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes
|
||||
{
|
||||
ReadUnmanagedSafe(out int length);
|
||||
value.Resize(length, NativeArrayOptions.UninitializedMemory);
|
||||
for (var i = 0; i < length; ++i)
|
||||
{
|
||||
ReadValueSafeInPlace(ref value.ElementAt(i));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -452,6 +452,42 @@ namespace Unity.Netcode
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write a NativeArray of INetworkSerializables
|
||||
/// </summary>
|
||||
/// <param name="array">The value to write</param>
|
||||
/// <param name="count"></param>
|
||||
/// <param name="offset"></param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public void WriteNetworkSerializable<T>(NativeArray<T> array, int count = -1, int offset = 0) where T : unmanaged, INetworkSerializable
|
||||
{
|
||||
int sizeInTs = count != -1 ? count : array.Length - offset;
|
||||
WriteValueSafe(sizeInTs);
|
||||
foreach (var item in array)
|
||||
{
|
||||
WriteNetworkSerializable(item);
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
/// <summary>
|
||||
/// Write a NativeList of INetworkSerializables
|
||||
/// </summary>
|
||||
/// <param name="array">The value to write</param>
|
||||
/// <param name="count"></param>
|
||||
/// <param name="offset"></param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public void WriteNetworkSerializable<T>(NativeList<T> array, int count = -1, int offset = 0) where T : unmanaged, INetworkSerializable
|
||||
{
|
||||
int sizeInTs = count != -1 ? count : array.Length - offset;
|
||||
WriteValueSafe(sizeInTs);
|
||||
foreach (var item in array)
|
||||
{
|
||||
WriteNetworkSerializable(item);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Writes a string
|
||||
/// </summary>
|
||||
@@ -536,6 +572,40 @@ namespace Unity.Netcode
|
||||
return sizeof(int) + sizeInBytes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the required size to write a NativeArray
|
||||
/// </summary>
|
||||
/// <param name="array">The array to write</param>
|
||||
/// <param name="count">The amount of elements to write</param>
|
||||
/// <param name="offset">Where in the array to start</param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int GetWriteSize<T>(NativeArray<T> array, int count = -1, int offset = 0) where T : unmanaged
|
||||
{
|
||||
int sizeInTs = count != -1 ? count : array.Length - offset;
|
||||
int sizeInBytes = sizeInTs * sizeof(T);
|
||||
return sizeof(int) + sizeInBytes;
|
||||
}
|
||||
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
/// <summary>
|
||||
/// Get the required size to write a NativeList
|
||||
/// </summary>
|
||||
/// <param name="array">The array to write</param>
|
||||
/// <param name="count">The amount of elements to write</param>
|
||||
/// <param name="offset">Where in the array to start</param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int GetWriteSize<T>(NativeList<T> array, int count = -1, int offset = 0) where T : unmanaged
|
||||
{
|
||||
int sizeInTs = count != -1 ? count : array.Length - offset;
|
||||
int sizeInBytes = sizeInTs * sizeof(T);
|
||||
return sizeof(int) + sizeInBytes;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Write a partial value. The specified number of bytes is written from the value and the rest is ignored.
|
||||
/// </summary>
|
||||
@@ -680,6 +750,32 @@ namespace Unity.Netcode
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write multiple bytes to the stream
|
||||
/// </summary>
|
||||
/// <param name="value">Value to write</param>
|
||||
/// <param name="size">Number of bytes to write</param>
|
||||
/// <param name="offset">Offset into the buffer to begin writing</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void WriteBytes(NativeArray<byte> value, int size = -1, int offset = 0)
|
||||
{
|
||||
byte* ptr = (byte*)value.GetUnsafePtr();
|
||||
WriteBytes(ptr, size == -1 ? value.Length : size, offset);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write multiple bytes to the stream
|
||||
/// </summary>
|
||||
/// <param name="value">Value to write</param>
|
||||
/// <param name="size">Number of bytes to write</param>
|
||||
/// <param name="offset">Offset into the buffer to begin writing</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void WriteBytes(NativeList<byte> value, int size = -1, int offset = 0)
|
||||
{
|
||||
byte* ptr = (byte*)value.GetUnsafePtr();
|
||||
WriteBytes(ptr, size == -1 ? value.Length : size, offset);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write multiple bytes to the stream
|
||||
///
|
||||
@@ -698,6 +794,32 @@ namespace Unity.Netcode
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write multiple bytes to the stream
|
||||
/// </summary>
|
||||
/// <param name="value">Value to write</param>
|
||||
/// <param name="size">Number of bytes to write</param>
|
||||
/// <param name="offset">Offset into the buffer to begin writing</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void WriteBytesSafe(NativeArray<byte> value, int size = -1, int offset = 0)
|
||||
{
|
||||
byte* ptr = (byte*)value.GetUnsafePtr();
|
||||
WriteBytesSafe(ptr, size == -1 ? value.Length : size, offset);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write multiple bytes to the stream
|
||||
/// </summary>
|
||||
/// <param name="value">Value to write</param>
|
||||
/// <param name="size">Number of bytes to write</param>
|
||||
/// <param name="offset">Offset into the buffer to begin writing</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void WriteBytesSafe(NativeList<byte> value, int size = -1, int offset = 0)
|
||||
{
|
||||
byte* ptr = (byte*)value.GetUnsafePtr();
|
||||
WriteBytesSafe(ptr, size == -1 ? value.Length : size, offset);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy the contents of this writer into another writer.
|
||||
/// The contents will be copied from the beginning of this writer to its current position.
|
||||
@@ -749,6 +871,44 @@ namespace Unity.Netcode
|
||||
return value.Length + sizeof(int);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the write size for an array of FixedStrings
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static int GetWriteSize<T>(in NativeArray<T> value)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes
|
||||
{
|
||||
var size = sizeof(int);
|
||||
foreach (var item in value)
|
||||
{
|
||||
size += sizeof(int) + item.Length;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
/// <summary>
|
||||
/// Get the write size for an array of FixedStrings
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static int GetWriteSize<T>(in NativeList<T> value)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes
|
||||
{
|
||||
var size = sizeof(int);
|
||||
foreach (var item in value)
|
||||
{
|
||||
size += sizeof(int) + item.Length;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Get the size required to write an unmanaged value of type T
|
||||
/// </summary>
|
||||
@@ -799,6 +959,50 @@ namespace Unity.Netcode
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal unsafe void WriteUnmanaged<T>(NativeArray<T> value) where T : unmanaged
|
||||
{
|
||||
WriteUnmanaged(value.Length);
|
||||
var ptr = (T*)value.GetUnsafePtr();
|
||||
{
|
||||
byte* bytes = (byte*)ptr;
|
||||
WriteBytes(bytes, sizeof(T) * value.Length);
|
||||
}
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal unsafe void WriteUnmanagedSafe<T>(NativeArray<T> value) where T : unmanaged
|
||||
{
|
||||
WriteUnmanagedSafe(value.Length);
|
||||
var ptr = (T*)value.GetUnsafePtr();
|
||||
{
|
||||
byte* bytes = (byte*)ptr;
|
||||
WriteBytesSafe(bytes, sizeof(T) * value.Length);
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal unsafe void WriteUnmanaged<T>(NativeList<T> value) where T : unmanaged
|
||||
{
|
||||
WriteUnmanaged(value.Length);
|
||||
var ptr = (T*)value.GetUnsafePtr();
|
||||
{
|
||||
byte* bytes = (byte*)ptr;
|
||||
WriteBytes(bytes, sizeof(T) * value.Length);
|
||||
}
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal unsafe void WriteUnmanagedSafe<T>(NativeList<T> value) where T : unmanaged
|
||||
{
|
||||
WriteUnmanagedSafe(value.Length);
|
||||
var ptr = (T*)value.GetUnsafePtr();
|
||||
{
|
||||
byte* bytes = (byte*)ptr;
|
||||
WriteBytesSafe(bytes, sizeof(T) * value.Length);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// This empty struct exists to allow overloading WriteValue based on generic constraints.
|
||||
/// At the bytecode level, constraints aren't included in the method signature, so if multiple
|
||||
@@ -869,6 +1073,20 @@ namespace Unity.Netcode
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This empty struct exists to allow overloading WriteValue based on generic constraints.
|
||||
/// At the bytecode level, constraints aren't included in the method signature, so if multiple
|
||||
/// methods exist with the same signature, it causes a compile error because they would end up
|
||||
/// being emitted as the same method, even if the constraints are different.
|
||||
/// Adding an empty struct with a default value gives them different signatures in the bytecode,
|
||||
/// which then allows the compiler to do overload resolution based on the generic constraints
|
||||
/// without the user having to pass the struct in themselves.
|
||||
/// </summary>
|
||||
public struct ForGeneric
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write a NetworkSerializable value
|
||||
/// </summary>
|
||||
@@ -929,6 +1147,50 @@ namespace Unity.Netcode
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void WriteValue<T>(T[] value, ForStructs unused = default) where T : unmanaged, INetworkSerializeByMemcpy => WriteUnmanaged(value);
|
||||
|
||||
/// <summary>
|
||||
/// Write a struct NativeArray
|
||||
/// </summary>
|
||||
/// <param name="value">The values to write</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution based on generic constraints</param>
|
||||
/// <typeparam name="T">The type being serialized</typeparam>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void WriteValue<T>(NativeArray<T> value, ForGeneric unused = default) where T : unmanaged
|
||||
{
|
||||
if (typeof(INetworkSerializable).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
// This calls WriteNetworkSerializable in a way that doesn't require
|
||||
// any boxing.
|
||||
NetworkVariableSerialization<NativeArray<T>>.Serializer.Write(this, ref value);
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteUnmanaged(value);
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
/// <summary>
|
||||
/// Write a struct NativeList
|
||||
/// </summary>
|
||||
/// <param name="value">The values to write</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution based on generic constraints</param>
|
||||
/// <typeparam name="T">The type being serialized</typeparam>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void WriteValue<T>(NativeList<T> value, ForGeneric unused = default) where T : unmanaged
|
||||
{
|
||||
if (typeof(INetworkSerializable).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
// This calls WriteNetworkSerializable in a way that doesn't require
|
||||
// any boxing.
|
||||
NetworkVariableSerialization<NativeList<T>>.Serializer.Write(this, ref value);
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteUnmanaged(value);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Write a struct
|
||||
///
|
||||
@@ -953,6 +1215,56 @@ namespace Unity.Netcode
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void WriteValueSafe<T>(T[] value, ForStructs unused = default) where T : unmanaged, INetworkSerializeByMemcpy => WriteUnmanagedSafe(value);
|
||||
|
||||
/// <summary>
|
||||
/// Write a struct NativeArray
|
||||
///
|
||||
/// "Safe" version - automatically performs bounds checking. Less efficient than bounds checking
|
||||
/// for multiple writes at once by calling TryBeginWrite.
|
||||
/// </summary>
|
||||
/// <param name="value">The values to write</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution based on generic constraints</param>
|
||||
/// <typeparam name="T">The type being serialized</typeparam>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void WriteValueSafe<T>(NativeArray<T> value, ForGeneric unused = default) where T : unmanaged
|
||||
{
|
||||
if (typeof(INetworkSerializable).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
// This calls WriteNetworkSerializable in a way that doesn't require
|
||||
// any boxing.
|
||||
NetworkVariableSerialization<NativeArray<T>>.Serializer.Write(this, ref value);
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteUnmanagedSafe(value);
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
/// <summary>
|
||||
/// Write a struct NativeList
|
||||
///
|
||||
/// "Safe" version - automatically performs bounds checking. Less efficient than bounds checking
|
||||
/// for multiple writes at once by calling TryBeginWrite.
|
||||
/// </summary>
|
||||
/// <param name="value">The values to write</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution based on generic constraints</param>
|
||||
/// <typeparam name="T">The type being serialized</typeparam>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void WriteValueSafe<T>(NativeList<T> value, ForGeneric unused = default) where T : unmanaged
|
||||
{
|
||||
if (typeof(INetworkSerializable).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
// This calls WriteNetworkSerializable in a way that doesn't require
|
||||
// any boxing.
|
||||
NetworkVariableSerialization<NativeList<T>>.Serializer.Write(this, ref value);
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteUnmanagedSafe(value);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Write a primitive value (int, bool, etc)
|
||||
/// Accepts any value that implements the given interfaces, but is not guaranteed to work correctly
|
||||
@@ -1185,7 +1497,6 @@ namespace Unity.Netcode
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void WriteValue(Ray2D[] value) => WriteUnmanaged(value);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Write a Vector2
|
||||
///
|
||||
@@ -1415,6 +1726,65 @@ namespace Unity.Netcode
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an array of FixedString values. Writes only the part of each string that's actually used.
|
||||
/// When calling TryBeginWrite, ensure you calculate the write size correctly (preferably by calling
|
||||
/// FastBufferWriter.GetWriteSize())
|
||||
/// </summary>
|
||||
/// <param name="value">the value to write</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution based on generic constraints</param>
|
||||
/// <typeparam name="T">The type being serialized</typeparam>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void WriteValue<T>(T[] value, ForFixedStrings unused = default)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes
|
||||
{
|
||||
WriteUnmanaged(value.Length);
|
||||
foreach (var str in value)
|
||||
{
|
||||
WriteValue(str);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write a NativeArray of FixedString values. Writes only the part of each string that's actually used.
|
||||
/// When calling TryBeginWrite, ensure you calculate the write size correctly (preferably by calling
|
||||
/// FastBufferWriter.GetWriteSize())
|
||||
/// </summary>
|
||||
/// <param name="value">the value to write</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution based on generic constraints</param>
|
||||
/// <typeparam name="T">The type being serialized</typeparam>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void WriteValue<T>(in NativeArray<T> value, ForFixedStrings unused = default)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes
|
||||
{
|
||||
WriteUnmanaged(value.Length);
|
||||
foreach (var str in value)
|
||||
{
|
||||
WriteValue(str);
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
/// <summary>
|
||||
/// Write a NativeList of FixedString values. Writes only the part of each string that's actually used.
|
||||
/// When calling TryBeginWrite, ensure you calculate the write size correctly (preferably by calling
|
||||
/// FastBufferWriter.GetWriteSize())
|
||||
/// </summary>
|
||||
/// <param name="value">the value to write</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution based on generic constraints</param>
|
||||
/// <typeparam name="T">The type being serialized</typeparam>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void WriteValue<T>(in NativeList<T> value, ForFixedStrings unused = default)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes
|
||||
{
|
||||
WriteUnmanaged(value.Length);
|
||||
foreach (var str in value)
|
||||
{
|
||||
WriteValue(str);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Write a FixedString value. Writes only the part of the string that's actually used.
|
||||
@@ -1435,5 +1805,76 @@ namespace Unity.Netcode
|
||||
}
|
||||
WriteValue(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write a NativeArray of FixedString values. Writes only the part of each string that's actually used.
|
||||
/// "Safe" version - automatically performs bounds checking. Less efficient than bounds checking
|
||||
/// for multiple writes at once by calling TryBeginWrite.
|
||||
/// </summary>
|
||||
/// <param name="value">the value to write</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution based on generic constraints</param>
|
||||
/// <typeparam name="T">The type being serialized</typeparam>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void WriteValueSafe<T>(T[] value, ForFixedStrings unused = default)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes
|
||||
{
|
||||
if (!TryBeginWriteInternal(GetWriteSize(value)))
|
||||
{
|
||||
throw new OverflowException("Writing past the end of the buffer");
|
||||
}
|
||||
WriteUnmanaged(value.Length);
|
||||
foreach (var str in value)
|
||||
{
|
||||
WriteValue(str);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write a NativeArray of FixedString values. Writes only the part of each string that's actually used.
|
||||
/// "Safe" version - automatically performs bounds checking. Less efficient than bounds checking
|
||||
/// for multiple writes at once by calling TryBeginWrite.
|
||||
/// </summary>
|
||||
/// <param name="value">the value to write</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution based on generic constraints</param>
|
||||
/// <typeparam name="T">The type being serialized</typeparam>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void WriteValueSafe<T>(in NativeArray<T> value)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes
|
||||
{
|
||||
if (!TryBeginWriteInternal(GetWriteSize(value)))
|
||||
{
|
||||
throw new OverflowException("Writing past the end of the buffer");
|
||||
}
|
||||
WriteUnmanaged(value.Length);
|
||||
foreach (var str in value)
|
||||
{
|
||||
WriteValue(str);
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
/// <summary>
|
||||
/// Write a NativeList of FixedString values. Writes only the part of each string that's actually used.
|
||||
/// "Safe" version - automatically performs bounds checking. Less efficient than bounds checking
|
||||
/// for multiple writes at once by calling TryBeginWrite.
|
||||
/// </summary>
|
||||
/// <param name="value">the value to write</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution based on generic constraints</param>
|
||||
/// <typeparam name="T">The type being serialized</typeparam>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void WriteValueSafe<T>(in NativeList<T> value)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes
|
||||
{
|
||||
if (!TryBeginWriteInternal(GetWriteSize(value)))
|
||||
{
|
||||
throw new OverflowException("Writing past the end of the buffer");
|
||||
}
|
||||
WriteUnmanaged(value.Length);
|
||||
foreach (var str in value)
|
||||
{
|
||||
WriteValue(str);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +96,25 @@ namespace Unity.Netcode
|
||||
/// <typeparam name="T">The type being serialized</typeparam>
|
||||
void SerializeValue<T>(ref T[] value, FastBufferWriter.ForStructs unused = default) where T : unmanaged, INetworkSerializeByMemcpy;
|
||||
|
||||
/// <summary>
|
||||
/// Read or write a NativeArray of struct values implementing ISerializeByMemcpy
|
||||
/// </summary>
|
||||
/// <param name="value">The values to read/write</param>
|
||||
/// <param name="allocator">The allocator to use to construct the resulting NativeArray when reading</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution based on generic constraints</param>
|
||||
/// <typeparam name="T">The type being serialized</typeparam>
|
||||
void SerializeValue<T>(ref NativeArray<T> value, Allocator allocator, FastBufferWriter.ForGeneric unused = default) where T : unmanaged;
|
||||
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
/// <summary>
|
||||
/// Read or write a NativeList of struct values implementing ISerializeByMemcpy
|
||||
/// </summary>
|
||||
/// <param name="value">The values to read/write</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution based on generic constraints</param>
|
||||
/// <typeparam name="T">The type being serialized</typeparam>
|
||||
void SerializeValue<T>(ref NativeList<T> value, FastBufferWriter.ForGeneric unused = default) where T : unmanaged;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Read or write a struct or class value implementing INetworkSerializable
|
||||
/// </summary>
|
||||
@@ -121,6 +140,27 @@ namespace Unity.Netcode
|
||||
void SerializeValue<T>(ref T value, FastBufferWriter.ForFixedStrings unused = default)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes;
|
||||
|
||||
/// <summary>
|
||||
/// Read or write NativeArray of FixedString values
|
||||
/// </summary>
|
||||
/// <param name="value">The value to read/write</param>
|
||||
/// <param name="allocator">The allocator to use to construct the resulting NativeArray when reading</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution based on generic constraints</param>
|
||||
/// <typeparam name="T">The type being serialized</typeparam>
|
||||
void SerializeValue<T>(ref NativeArray<T> value, Allocator allocator)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes;
|
||||
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
/// <summary>
|
||||
/// Read or write a NativeList of FixedString values
|
||||
/// </summary>
|
||||
/// <param name="value">The value to read/write</param>
|
||||
/// <param name="unused">An unused parameter used for enabling overload resolution based on generic constraints</param>
|
||||
/// <typeparam name="T">The type being serialized</typeparam>
|
||||
void SerializeValue<T>(ref NativeList<T> value)
|
||||
where T : unmanaged, INativeList<byte>, IUTF8Bytes;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Read or write a Vector2 value
|
||||
/// </summary>
|
||||
@@ -344,6 +384,31 @@ namespace Unity.Netcode
|
||||
/// <param name="unused">An unused parameter that can be used for enabling overload resolution based on generic constraints</param>
|
||||
void SerializeValuePreChecked<T>(ref T[] value, FastBufferWriter.ForStructs unused = default) where T : unmanaged, INetworkSerializeByMemcpy;
|
||||
|
||||
/// <summary>
|
||||
/// Serialize a NativeArray of structs, "pre-checked", which skips buffer checks.
|
||||
/// In debug and editor builds, a check is made to ensure you've called "PreCheck" before
|
||||
/// calling this. In release builds, calling this without calling "PreCheck" may read or write
|
||||
/// past the end of the buffer, which will cause memory corruption and undefined behavior.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type being serialized</typeparam>
|
||||
/// <param name="value">The values to read/write</param>
|
||||
/// <param name="allocator">The allocator to use to construct the resulting NativeArray when reading</param>
|
||||
/// <param name="unused">An unused parameter that can be used for enabling overload resolution based on generic constraints</param>
|
||||
void SerializeValuePreChecked<T>(ref NativeArray<T> value, Allocator allocator, FastBufferWriter.ForGeneric unused = default) where T : unmanaged;
|
||||
|
||||
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
|
||||
/// <summary>
|
||||
/// Serialize a NativeList of structs, "pre-checked", which skips buffer checks.
|
||||
/// In debug and editor builds, a check is made to ensure you've called "PreCheck" before
|
||||
/// calling this. In release builds, calling this without calling "PreCheck" may read or write
|
||||
/// past the end of the buffer, which will cause memory corruption and undefined behavior.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type being serialized</typeparam>
|
||||
/// <param name="value">The values to read/write</param>
|
||||
/// <param name="unused">An unused parameter that can be used for enabling overload resolution based on generic constraints</param>
|
||||
void SerializeValuePreChecked<T>(ref NativeList<T> value, FastBufferWriter.ForGeneric unused = default) where T : unmanaged;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Serialize a FixedString, "pre-checked", which skips buffer checks.
|
||||
/// In debug and editor builds, a check is made to ensure you've called "PreCheck" before
|
||||
@@ -438,7 +503,7 @@ namespace Unity.Netcode
|
||||
void SerializeValuePreChecked(ref Vector4 value);
|
||||
|
||||
/// <summary>
|
||||
/// Serialize a Vector4Array, "pre-checked", which skips buffer checks.
|
||||
/// Serialize a Vector4 array, "pre-checked", which skips buffer checks.
|
||||
/// In debug and editor builds, a check is made to ensure you've called "PreCheck" before
|
||||
/// calling this. In release builds, calling this without calling "PreCheck" may read or write
|
||||
/// past the end of the buffer, which will cause memory corruption and undefined behavior.
|
||||
|
||||
Reference in New Issue
Block a user