com.unity.netcode.gameobjects@1.0.0-pre.8
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.0.0-pre.8] - 2022-04-27 ### Changed - `unmanaged` structs are no longer universally accepted as RPC parameters because some structs (i.e., structs with pointers in them, such as `NativeList<T>`) can't be supported by the default memcpy struct serializer. Structs that are intended to be serialized across the network must add `INetworkSerializeByMemcpy` to the interface list (i.e., `struct Foo : INetworkSerializeByMemcpy`). This interface is empty and just serves to mark the struct as compatible with memcpy serialization. For external structs you can't edit, you can pass them to RPCs by wrapping them in `ForceNetworkSerializeByMemcpy<T>`. (#1901) ### Removed - Removed `SIPTransport` (#1870) - Removed `ClientNetworkTransform` from the package samples and moved to Boss Room's Utilities package which can be found [here](https://github.com/Unity-Technologies/com.unity.multiplayer.samples.coop/blob/main/Packages/com.unity.multiplayer.samples.coop/Utilities/Net/ClientAuthority/ClientNetworkTransform.cs). ### Fixed - Fixed `NetworkTransform` generating false positive rotation delta checks when rolling over between 0 and 360 degrees. (#1890) - Fixed client throwing an exception if it has messages in the outbound queue when processing the `NetworkEvent.Disconnect` event and is using UTP. (#1884) - Fixed issue during client synchronization if 'ValidateSceneBeforeLoading' returned false it would halt the client synchronization process resulting in a client that was approved but not synchronized or fully connected with the server. (#1883) - Fixed an issue where UNetTransport.StartServer would return success even if the underlying transport failed to start (#854) - Passing generic types to RPCs no longer causes a native crash (#1901) - Fixed an issue where calling `Shutdown` on a `NetworkManager` that was already shut down would cause an immediate shutdown the next time it was started (basically the fix makes `Shutdown` idempotent). (#1877)
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Unity.Netcode
|
||||
{
|
||||
/// <summary>
|
||||
/// Two-way serializer wrapping FastBufferReader or FastBufferWriter.
|
||||
///
|
||||
///
|
||||
/// Implemented as a ref struct for two reasons:
|
||||
/// 1. The BufferSerializer cannot outlive the FBR/FBW it wraps or using it will cause a crash
|
||||
/// 2. The BufferSerializer must always be passed by reference and can't be copied
|
||||
///
|
||||
/// Ref structs help enforce both of those rules: they can't out live the stack context in which they were
|
||||
/// Ref structs help enforce both of those rules: they can't ref live the stack context in which they were
|
||||
/// created, and they're always passed by reference no matter what.
|
||||
///
|
||||
/// BufferSerializer doesn't wrapp FastBufferReader or FastBufferWriter directly because it can't.
|
||||
@@ -58,168 +61,63 @@ namespace Unity.Netcode
|
||||
return m_Implementation.GetFastBufferWriter();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serialize an INetworkSerializable
|
||||
///
|
||||
/// Throws OverflowException if the end of the buffer has been reached.
|
||||
/// Write buffers will grow up to the maximum allowable message size before throwing OverflowException.
|
||||
/// </summary>
|
||||
/// <param name="value">Value to serialize</param>
|
||||
public void SerializeNetworkSerializable<T>(ref T value) where T : INetworkSerializable, new()
|
||||
{
|
||||
m_Implementation.SerializeNetworkSerializable(ref value);
|
||||
}
|
||||
public void SerializeValue(ref string s, bool oneByteChars = false) => m_Implementation.SerializeValue(ref s, oneByteChars);
|
||||
public void SerializeValue(ref byte value) => m_Implementation.SerializeValue(ref value);
|
||||
public void SerializeValue<T>(ref T value, FastBufferWriter.ForPrimitives unused = default) where T : unmanaged, IComparable, IConvertible, IComparable<T>, IEquatable<T> => m_Implementation.SerializeValue(ref value);
|
||||
public void SerializeValue<T>(ref T[] value, FastBufferWriter.ForPrimitives unused = default) where T : unmanaged, IComparable, IConvertible, IComparable<T>, IEquatable<T> => m_Implementation.SerializeValue(ref value);
|
||||
public void SerializeValue<T>(ref T value, FastBufferWriter.ForEnums unused = default) where T : unmanaged, Enum => m_Implementation.SerializeValue(ref value);
|
||||
public void SerializeValue<T>(ref T[] value, FastBufferWriter.ForEnums unused = default) where T : unmanaged, Enum => m_Implementation.SerializeValue(ref value);
|
||||
public void SerializeValue<T>(ref T value, FastBufferWriter.ForStructs unused = default) where T : unmanaged, INetworkSerializeByMemcpy => m_Implementation.SerializeValue(ref value);
|
||||
public void SerializeValue<T>(ref T[] value, FastBufferWriter.ForStructs unused = default) where T : unmanaged, INetworkSerializeByMemcpy => m_Implementation.SerializeValue(ref value);
|
||||
public void SerializeValue<T>(ref T value, FastBufferWriter.ForNetworkSerializable unused = default) where T : INetworkSerializable, new() => m_Implementation.SerializeValue(ref value);
|
||||
public void SerializeValue<T>(ref T[] value, FastBufferWriter.ForNetworkSerializable unused = default) where T : INetworkSerializable, new() => m_Implementation.SerializeValue(ref value);
|
||||
public void SerializeValue(ref Vector2 value) => m_Implementation.SerializeValue(ref value);
|
||||
public void SerializeValue(ref Vector2[] value) => m_Implementation.SerializeValue(ref value);
|
||||
public void SerializeValue(ref Vector3 value) => m_Implementation.SerializeValue(ref value);
|
||||
public void SerializeValue(ref Vector3[] value) => m_Implementation.SerializeValue(ref value);
|
||||
public void SerializeValue(ref Vector4 value) => m_Implementation.SerializeValue(ref value);
|
||||
public void SerializeValue(ref Vector4[] value) => m_Implementation.SerializeValue(ref value);
|
||||
public void SerializeValue(ref Quaternion value) => m_Implementation.SerializeValue(ref value);
|
||||
public void SerializeValue(ref Quaternion[] value) => m_Implementation.SerializeValue(ref value);
|
||||
public void SerializeValue(ref Color value) => m_Implementation.SerializeValue(ref value);
|
||||
public void SerializeValue(ref Color[] value) => m_Implementation.SerializeValue(ref value);
|
||||
public void SerializeValue(ref Color32 value) => m_Implementation.SerializeValue(ref value);
|
||||
public void SerializeValue(ref Color32[] value) => m_Implementation.SerializeValue(ref value);
|
||||
public void SerializeValue(ref Ray value) => m_Implementation.SerializeValue(ref value);
|
||||
public void SerializeValue(ref Ray[] value) => m_Implementation.SerializeValue(ref value);
|
||||
public void SerializeValue(ref Ray2D value) => m_Implementation.SerializeValue(ref value);
|
||||
public void SerializeValue(ref Ray2D[] value) => m_Implementation.SerializeValue(ref value);
|
||||
|
||||
/// <summary>
|
||||
/// Serialize a string.
|
||||
///
|
||||
/// Note: Will ALWAYS allocate a new string when reading.
|
||||
///
|
||||
/// Throws OverflowException if the end of the buffer has been reached.
|
||||
/// Write buffers will grow up to the maximum allowable message size before throwing OverflowException.
|
||||
/// </summary>
|
||||
/// <param name="s">Value to serialize</param>
|
||||
/// <param name="oneByteChars">
|
||||
/// If true, will truncate each char to one byte.
|
||||
/// This is slower than two-byte chars, but uses less bandwidth.
|
||||
/// </param>
|
||||
public void SerializeValue(ref string s, bool oneByteChars = false)
|
||||
{
|
||||
m_Implementation.SerializeValue(ref s, oneByteChars);
|
||||
}
|
||||
public void SerializeNetworkSerializable<T>(ref T value) where T : INetworkSerializable, new() => m_Implementation.SerializeNetworkSerializable(ref value);
|
||||
|
||||
/// <summary>
|
||||
/// Serialize an array value.
|
||||
///
|
||||
/// Note: Will ALWAYS allocate a new array when reading.
|
||||
/// If you have a statically-sized array that you know is large enough, it's recommended to
|
||||
/// serialize the size yourself and iterate serializing array members.
|
||||
///
|
||||
/// (This is because C# doesn't allow setting an array's length value, so deserializing
|
||||
/// into an existing array of larger size would result in an array that doesn't have as many values
|
||||
/// as its Length indicates it should.)
|
||||
///
|
||||
/// Throws OverflowException if the end of the buffer has been reached.
|
||||
/// Write buffers will grow up to the maximum allowable message size before throwing OverflowException.
|
||||
/// </summary>
|
||||
/// <param name="array">Value to serialize</param>
|
||||
public void SerializeValue<T>(ref T[] array) where T : unmanaged
|
||||
{
|
||||
m_Implementation.SerializeValue(ref array);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serialize a single byte
|
||||
///
|
||||
/// Throws OverflowException if the end of the buffer has been reached.
|
||||
/// Write buffers will grow up to the maximum allowable message size before throwing OverflowException.
|
||||
/// </summary>
|
||||
/// <param name="value">Value to serialize</param>
|
||||
public void SerializeValue(ref byte value)
|
||||
{
|
||||
m_Implementation.SerializeValue(ref value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serialize an unmanaged type. Supports basic value types as well as structs.
|
||||
/// The provided type will be copied to/from the buffer as it exists in memory.
|
||||
///
|
||||
/// Throws OverflowException if the end of the buffer has been reached.
|
||||
/// Write buffers will grow up to the maximum allowable message size before throwing OverflowException.
|
||||
/// </summary>
|
||||
/// <param name="value">Value to serialize</param>
|
||||
public void SerializeValue<T>(ref T value) where T : unmanaged
|
||||
{
|
||||
m_Implementation.SerializeValue(ref value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows faster serialization by batching bounds checking.
|
||||
/// When you know you will be writing multiple fields back-to-back and you know the total size,
|
||||
/// you can call PreCheck() once on the total size, and then follow it with calls to
|
||||
/// SerializeValuePreChecked() for faster serialization. Write buffers will grow during PreCheck()
|
||||
/// if needed.
|
||||
///
|
||||
/// PreChecked serialization operations will throw OverflowException in editor and development builds if you
|
||||
/// go past the point you've marked using PreCheck(). In release builds, OverflowException will not be thrown
|
||||
/// for performance reasons, since the point of using PreCheck is to avoid bounds checking in the following
|
||||
/// operations in release builds.
|
||||
///
|
||||
/// To get the correct size to check for, use FastBufferWriter.GetWriteSize(value) or
|
||||
/// FastBufferWriter.GetWriteSize<type>()
|
||||
/// </summary>
|
||||
/// <param name="amount">Number of bytes you plan to read or write</param>
|
||||
/// <returns>True if the read/write can proceed, false otherwise.</returns>
|
||||
public bool PreCheck(int amount)
|
||||
{
|
||||
return m_Implementation.PreCheck(amount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serialize a string.
|
||||
///
|
||||
/// Note: Will ALWAYS allocate a new string when reading.
|
||||
///
|
||||
/// Using the PreChecked versions of these functions requires calling PreCheck() ahead of time, and they should only
|
||||
/// be called if PreCheck() returns true. This is an efficiency option, as it allows you to PreCheck() multiple
|
||||
/// serialization operations in one function call instead of having to do bounds checking on every call.
|
||||
/// </summary>
|
||||
/// <param name="s">Value to serialize</param>
|
||||
/// <param name="oneByteChars">
|
||||
/// If true, will truncate each char to one byte.
|
||||
/// This is slower than two-byte chars, but uses less bandwidth.
|
||||
/// </param>
|
||||
public void SerializeValuePreChecked(ref string s, bool oneByteChars = false)
|
||||
{
|
||||
m_Implementation.SerializeValuePreChecked(ref s, oneByteChars);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serialize an array value.
|
||||
///
|
||||
/// Note: Will ALWAYS allocate a new array when reading.
|
||||
/// If you have a statically-sized array that you know is large enough, it's recommended to
|
||||
/// serialize the size yourself and iterate serializing array members.
|
||||
///
|
||||
/// (This is because C# doesn't allow setting an array's length value, so deserializing
|
||||
/// into an existing array of larger size would result in an array that doesn't have as many values
|
||||
/// as its Length indicates it should.)
|
||||
///
|
||||
/// Using the PreChecked versions of these functions requires calling PreCheck() ahead of time, and they should only
|
||||
/// be called if PreCheck() returns true. This is an efficiency option, as it allows you to PreCheck() multiple
|
||||
/// serialization operations in one function call instead of having to do bounds checking on every call.
|
||||
/// </summary>
|
||||
/// <param name="array">Value to serialize</param>
|
||||
public void SerializeValuePreChecked<T>(ref T[] array) where T : unmanaged
|
||||
{
|
||||
m_Implementation.SerializeValuePreChecked(ref array);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serialize a single byte
|
||||
///
|
||||
/// Using the PreChecked versions of these functions requires calling PreCheck() ahead of time, and they should only
|
||||
/// be called if PreCheck() returns true. This is an efficiency option, as it allows you to PreCheck() multiple
|
||||
/// serialization operations in one function call instead of having to do bounds checking on every call.
|
||||
/// </summary>
|
||||
/// <param name="value">Value to serialize</param>
|
||||
public void SerializeValuePreChecked(ref byte value)
|
||||
{
|
||||
m_Implementation.SerializeValuePreChecked(ref value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serialize an unmanaged type. Supports basic value types as well as structs.
|
||||
/// The provided type will be copied to/from the buffer as it exists in memory.
|
||||
///
|
||||
/// Using the PreChecked versions of these functions requires calling PreCheck() ahead of time, and they should only
|
||||
/// be called if PreCheck() returns true. This is an efficiency option, as it allows you to PreCheck() multiple
|
||||
/// serialization operations in one function call instead of having to do bounds checking on every call.
|
||||
/// </summary>
|
||||
/// <param name="value">Value to serialize</param>
|
||||
public void SerializeValuePreChecked<T>(ref T value) where T : unmanaged
|
||||
{
|
||||
m_Implementation.SerializeValuePreChecked(ref value);
|
||||
}
|
||||
public void SerializeValuePreChecked(ref string s, bool oneByteChars = false) => m_Implementation.SerializeValuePreChecked(ref s, oneByteChars);
|
||||
public void SerializeValuePreChecked(ref byte value) => m_Implementation.SerializeValuePreChecked(ref value);
|
||||
public void SerializeValuePreChecked<T>(ref T value, FastBufferWriter.ForPrimitives unused = default) where T : unmanaged, IComparable, IConvertible, IComparable<T>, IEquatable<T> => m_Implementation.SerializeValuePreChecked(ref value);
|
||||
public void SerializeValuePreChecked<T>(ref T[] value, FastBufferWriter.ForPrimitives unused = default) where T : unmanaged, IComparable, IConvertible, IComparable<T>, IEquatable<T> => m_Implementation.SerializeValuePreChecked(ref value);
|
||||
public void SerializeValuePreChecked<T>(ref T value, FastBufferWriter.ForEnums unused = default) where T : unmanaged, Enum => m_Implementation.SerializeValuePreChecked(ref value);
|
||||
public void SerializeValuePreChecked<T>(ref T[] value, FastBufferWriter.ForEnums unused = default) where T : unmanaged, Enum => m_Implementation.SerializeValuePreChecked(ref value);
|
||||
public void SerializeValuePreChecked<T>(ref T value, FastBufferWriter.ForStructs unused = default) where T : unmanaged, INetworkSerializeByMemcpy => m_Implementation.SerializeValuePreChecked(ref value);
|
||||
public void SerializeValuePreChecked<T>(ref T[] value, FastBufferWriter.ForStructs unused = default) where T : unmanaged, INetworkSerializeByMemcpy => m_Implementation.SerializeValuePreChecked(ref value);
|
||||
public void SerializeValuePreChecked(ref Vector2 value) => m_Implementation.SerializeValuePreChecked(ref value);
|
||||
public void SerializeValuePreChecked(ref Vector2[] value) => m_Implementation.SerializeValuePreChecked(ref value);
|
||||
public void SerializeValuePreChecked(ref Vector3 value) => m_Implementation.SerializeValuePreChecked(ref value);
|
||||
public void SerializeValuePreChecked(ref Vector3[] value) => m_Implementation.SerializeValuePreChecked(ref value);
|
||||
public void SerializeValuePreChecked(ref Vector4 value) => m_Implementation.SerializeValuePreChecked(ref value);
|
||||
public void SerializeValuePreChecked(ref Vector4[] value) => m_Implementation.SerializeValuePreChecked(ref value);
|
||||
public void SerializeValuePreChecked(ref Quaternion value) => m_Implementation.SerializeValuePreChecked(ref value);
|
||||
public void SerializeValuePreChecked(ref Quaternion[] value) => m_Implementation.SerializeValuePreChecked(ref value);
|
||||
public void SerializeValuePreChecked(ref Color value) => m_Implementation.SerializeValuePreChecked(ref value);
|
||||
public void SerializeValuePreChecked(ref Color[] value) => m_Implementation.SerializeValuePreChecked(ref value);
|
||||
public void SerializeValuePreChecked(ref Color32 value) => m_Implementation.SerializeValuePreChecked(ref value);
|
||||
public void SerializeValuePreChecked(ref Color32[] value) => m_Implementation.SerializeValuePreChecked(ref value);
|
||||
public void SerializeValuePreChecked(ref Ray value) => m_Implementation.SerializeValuePreChecked(ref value);
|
||||
public void SerializeValuePreChecked(ref Ray[] value) => m_Implementation.SerializeValuePreChecked(ref value);
|
||||
public void SerializeValuePreChecked(ref Ray2D value) => m_Implementation.SerializeValuePreChecked(ref value);
|
||||
public void SerializeValuePreChecked(ref Ray2D[] value) => m_Implementation.SerializeValuePreChecked(ref value);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user