diff --git a/com.unity.netcode.gameobjects/CHANGELOG.md b/com.unity.netcode.gameobjects/CHANGELOG.md index a85d578e27..f8f71725f8 100644 --- a/com.unity.netcode.gameobjects/CHANGELOG.md +++ b/com.unity.netcode.gameobjects/CHANGELOG.md @@ -9,6 +9,8 @@ Additional documentation and release notes are available at [Multiplayer Documen ## [Unreleased] ### Added +- Added serializer for `Pose` (#2675) + ### Fixed - Fixed issue where `NetworkAnimator` was not internally tracking changes to layer weights which prevented proper layer weight synchronization back to the original layer weight value. (#2674) diff --git a/com.unity.netcode.gameobjects/Editor/CodeGen/CodeGenHelpers.cs b/com.unity.netcode.gameobjects/Editor/CodeGen/CodeGenHelpers.cs index 1bb3ab1b16..4b05d387ed 100644 --- a/com.unity.netcode.gameobjects/Editor/CodeGen/CodeGenHelpers.cs +++ b/com.unity.netcode.gameobjects/Editor/CodeGen/CodeGenHelpers.cs @@ -41,6 +41,7 @@ internal static class CodeGenHelpers public static readonly string UnityVector3_FullName = typeof(Vector3).FullName; public static readonly string UnityVector4_FullName = typeof(Vector4).FullName; public static readonly string UnityQuaternion_FullName = typeof(Quaternion).FullName; + public static readonly string UnityPose_FullName = typeof(Pose).FullName; public static readonly string UnityRay_FullName = typeof(Ray).FullName; public static readonly string UnityRay2D_FullName = typeof(Ray2D).FullName; @@ -305,6 +306,11 @@ public static bool IsSerializable(this TypeReference typeReference) return true; } + if (typeReference.FullName == UnityPose_FullName) + { + return true; + } + if (typeReference.FullName == UnityRay_FullName) { return true; diff --git a/com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs b/com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs index 03999db128..d53bd44053 100644 --- a/com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs +++ b/com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs @@ -434,6 +434,7 @@ private void CreateNetworkVariableTypeInitializers(AssemblyDefinition assembly) typeof(Vector3Int), typeof(Vector4), typeof(Quaternion), + typeof(Pose), typeof(Color), typeof(Color32), typeof(Ray), diff --git a/com.unity.netcode.gameobjects/Runtime/Serialization/BufferSerializer.cs b/com.unity.netcode.gameobjects/Runtime/Serialization/BufferSerializer.cs index 85cc0909e0..0aa0eb7647 100644 --- a/com.unity.netcode.gameobjects/Runtime/Serialization/BufferSerializer.cs +++ b/com.unity.netcode.gameobjects/Runtime/Serialization/BufferSerializer.cs @@ -231,6 +231,18 @@ public FastBufferWriter GetFastBufferWriter() /// The values to read/write public void SerializeValue(ref Quaternion[] value) => m_Implementation.SerializeValue(ref value); + /// + /// Read or write a Pose value + /// + /// The value to read/write + public void SerializeValue(ref Pose value) => m_Implementation.SerializeValue(ref value); + + /// + /// Read or write an array of Pose values + /// + /// The values to read/write + public void SerializeValue(ref Pose[] value) => m_Implementation.SerializeValue(ref value); + /// /// Read or write a Color value /// @@ -555,6 +567,24 @@ public bool PreCheck(int amount) /// The value to read/write public void SerializeValuePreChecked(ref Quaternion[] value) => m_Implementation.SerializeValuePreChecked(ref value); + /// + /// Serialize a Pose, "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. + /// + /// The value to read/write + public void SerializeValuePreChecked(ref Pose value) => m_Implementation.SerializeValuePreChecked(ref value); + + /// + /// Serialize a Pose 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. + /// + /// The value to read/write + public void SerializeValuePreChecked(ref Pose[] value) => m_Implementation.SerializeValuePreChecked(ref value); + /// /// Serialize a Color, "pre-checked", which skips buffer checks. /// In debug and editor builds, a check is made to ensure you've called "PreCheck" before diff --git a/com.unity.netcode.gameobjects/Runtime/Serialization/BufferSerializerReader.cs b/com.unity.netcode.gameobjects/Runtime/Serialization/BufferSerializerReader.cs index d41d81b160..ffaa2ea9c6 100644 --- a/com.unity.netcode.gameobjects/Runtime/Serialization/BufferSerializerReader.cs +++ b/com.unity.netcode.gameobjects/Runtime/Serialization/BufferSerializerReader.cs @@ -71,6 +71,9 @@ public void SerializeValue(ref T value, FastBufferWriter.ForFixedStrings unus 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 Pose value) => m_Reader.ReadValueSafe(out value); + public void SerializeValue(ref Pose[] 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); @@ -127,6 +130,9 @@ public void SerializeValuePreChecked(ref T value, FastBufferWriter.ForFixedSt 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 Pose value) => m_Reader.ReadValue(out value); + public void SerializeValuePreChecked(ref Pose[] 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); diff --git a/com.unity.netcode.gameobjects/Runtime/Serialization/BufferSerializerWriter.cs b/com.unity.netcode.gameobjects/Runtime/Serialization/BufferSerializerWriter.cs index fd3b0c68fb..4c3b338009 100644 --- a/com.unity.netcode.gameobjects/Runtime/Serialization/BufferSerializerWriter.cs +++ b/com.unity.netcode.gameobjects/Runtime/Serialization/BufferSerializerWriter.cs @@ -70,6 +70,9 @@ public void SerializeValue(ref T value, FastBufferWriter.ForFixedStrings unus public void SerializeValue(ref Quaternion value) => m_Writer.WriteValueSafe(value); public void SerializeValue(ref Quaternion[] value) => m_Writer.WriteValueSafe(value); + public void SerializeValue(ref Pose value) => m_Writer.WriteValueSafe(value); + public void SerializeValue(ref Pose[] 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); @@ -128,6 +131,9 @@ public void SerializeValuePreChecked(ref T value, FastBufferWriter.ForFixedSt public void SerializeValuePreChecked(ref Quaternion value) => m_Writer.WriteValue(value); public void SerializeValuePreChecked(ref Quaternion[] value) => m_Writer.WriteValue(value); + public void SerializeValuePreChecked(ref Pose value) => m_Writer.WriteValue(value); + public void SerializeValuePreChecked(ref Pose[] 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); diff --git a/com.unity.netcode.gameobjects/Runtime/Serialization/BytePacker.cs b/com.unity.netcode.gameobjects/Runtime/Serialization/BytePacker.cs index 58b7ea1e33..beac746919 100644 --- a/com.unity.netcode.gameobjects/Runtime/Serialization/BytePacker.cs +++ b/com.unity.netcode.gameobjects/Runtime/Serialization/BytePacker.cs @@ -259,6 +259,23 @@ public static void WriteValuePacked(FastBufferWriter writer, Quaternion rotation WriteValuePacked(writer, rotation.w); } + /// + /// Writes the pose to the buffer. + /// + /// The writer to write to + /// Pose to write + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void WriteValuePacked(FastBufferWriter writer, Pose pose) + { + WriteValuePacked(writer, pose.position.x); + WriteValuePacked(writer, pose.position.y); + WriteValuePacked(writer, pose.position.z); + WriteValuePacked(writer, pose.rotation.x); + WriteValuePacked(writer, pose.rotation.y); + WriteValuePacked(writer, pose.rotation.z); + WriteValuePacked(writer, pose.rotation.w); + } + /// /// Writes a string in a packed format /// diff --git a/com.unity.netcode.gameobjects/Runtime/Serialization/ByteUnpacker.cs b/com.unity.netcode.gameobjects/Runtime/Serialization/ByteUnpacker.cs index 2d2cd88716..7317223b6d 100644 --- a/com.unity.netcode.gameobjects/Runtime/Serialization/ByteUnpacker.cs +++ b/com.unity.netcode.gameobjects/Runtime/Serialization/ByteUnpacker.cs @@ -278,6 +278,24 @@ public static void ReadValuePacked(FastBufferReader reader, out Quaternion rotat ReadValuePacked(reader, out rotation.w); } + /// + /// Reads the pose from the stream. + /// + /// The reader to read from + /// Pose to read + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void ReadValuePacked(FastBufferReader reader, out Pose pose) + { + pose = new Pose(); + ReadValuePacked(reader, out pose.position.x); + ReadValuePacked(reader, out pose.position.y); + ReadValuePacked(reader, out pose.position.z); + ReadValuePacked(reader, out pose.rotation.x); + ReadValuePacked(reader, out pose.rotation.y); + ReadValuePacked(reader, out pose.rotation.z); + ReadValuePacked(reader, out pose.rotation.w); + } + /// /// Reads a string in a packed format /// diff --git a/com.unity.netcode.gameobjects/Runtime/Serialization/FastBufferReader.cs b/com.unity.netcode.gameobjects/Runtime/Serialization/FastBufferReader.cs index f91a41e082..5917e5941c 100644 --- a/com.unity.netcode.gameobjects/Runtime/Serialization/FastBufferReader.cs +++ b/com.unity.netcode.gameobjects/Runtime/Serialization/FastBufferReader.cs @@ -1249,6 +1249,20 @@ public void ReadValueSafeInPlace(ref NativeList value, FastBufferWriter.Fo [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ReadValue(out Quaternion[] value) => ReadUnmanaged(out value); + /// + /// Read a Pose + /// + /// the value to read + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void ReadValue(out Pose value) => ReadUnmanaged(out value); + + /// + /// Read a Pose array + /// + /// the values to read + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void ReadValue(out Pose[] value) => ReadUnmanaged(out value); + /// /// Read a Color /// @@ -1426,6 +1440,26 @@ public void ReadValueSafeInPlace(ref NativeList value, FastBufferWriter.Fo [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ReadValueSafe(out Quaternion[] value) => ReadUnmanagedSafe(out value); + /// + /// Read a Pose + /// + /// "Safe" version - automatically performs bounds checking. Less efficient than bounds checking + /// for multiple reads at once by calling TryBeginRead. + /// + /// the value to read + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void ReadValueSafe(out Pose value) => ReadUnmanagedSafe(out value); + + /// + /// Read a Pose array + /// + /// "Safe" version - automatically performs bounds checking. Less efficient than bounds checking + /// for multiple reads at once by calling TryBeginRead. + /// + /// the values to read + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void ReadValueSafe(out Pose[] value) => ReadUnmanagedSafe(out value); + /// /// Read a Color /// diff --git a/com.unity.netcode.gameobjects/Runtime/Serialization/FastBufferWriter.cs b/com.unity.netcode.gameobjects/Runtime/Serialization/FastBufferWriter.cs index 475b00a91b..a0106cda97 100644 --- a/com.unity.netcode.gameobjects/Runtime/Serialization/FastBufferWriter.cs +++ b/com.unity.netcode.gameobjects/Runtime/Serialization/FastBufferWriter.cs @@ -1441,6 +1441,20 @@ public void WriteValueSafe(NativeList value, ForGeneric unused = default) [MethodImpl(MethodImplOptions.AggressiveInlining)] public void WriteValue(Quaternion[] value) => WriteUnmanaged(value); + /// + /// Write a Pose + /// + /// the value to write + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void WriteValue(in Pose value) => WriteUnmanaged(value); + + /// + /// Write a Pose array + /// + /// the values to write + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void WriteValue(Pose[] value) => WriteUnmanaged(value); + /// /// Write a Color /// @@ -1617,6 +1631,26 @@ public void WriteValueSafe(NativeList value, ForGeneric unused = default) [MethodImpl(MethodImplOptions.AggressiveInlining)] public void WriteValueSafe(Quaternion[] value) => WriteUnmanagedSafe(value); + /// + /// Write a Pose + /// + /// "Safe" version - automatically performs bounds checking. Less efficient than bounds checking + /// for multiple writes at once by calling TryBeginWrite. + /// + /// the value to write + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void WriteValueSafe(in Pose value) => WriteUnmanagedSafe(value); + + /// + /// Write a Pose array + /// + /// "Safe" version - automatically performs bounds checking. Less efficient than bounds checking + /// for multiple writes at once by calling TryBeginWrite. + /// + /// the values to write + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void WriteValueSafe(Pose[] value) => WriteUnmanagedSafe(value); + /// /// Write a Color /// diff --git a/com.unity.netcode.gameobjects/Runtime/Serialization/IReaderWriter.cs b/com.unity.netcode.gameobjects/Runtime/Serialization/IReaderWriter.cs index bdddec4924..d8f9da9a78 100644 --- a/com.unity.netcode.gameobjects/Runtime/Serialization/IReaderWriter.cs +++ b/com.unity.netcode.gameobjects/Runtime/Serialization/IReaderWriter.cs @@ -233,6 +233,18 @@ void SerializeValue(ref NativeList value) /// The values to read/write void SerializeValue(ref Quaternion[] value); + /// + /// Read or write a Pose value + /// + /// The value to read/write + void SerializeValue(ref Pose value); + + /// + /// Read or write an array of Pose values + /// + /// The values to read/write + void SerializeValue(ref Pose[] value); + /// /// Read or write a Color value /// @@ -529,6 +541,24 @@ void SerializeValuePreChecked(ref T value, FastBufferWriter.ForFixedStrings u /// The value to read/write void SerializeValuePreChecked(ref Quaternion[] value); + /// + /// Serialize a Pose, "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. + /// + /// The value to read/write + void SerializeValuePreChecked(ref Pose value); + + /// + /// Serialize a Pose 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. + /// + /// The value to read/write + void SerializeValuePreChecked(ref Pose[] value); + /// /// Serialize a Color, "pre-checked", which skips buffer checks. /// In debug and editor builds, a check is made to ensure you've called "PreCheck" before diff --git a/com.unity.netcode.gameobjects/Tests/Editor/Serialization/BaseFastBufferReaderWriterTest.cs b/com.unity.netcode.gameobjects/Tests/Editor/Serialization/BaseFastBufferReaderWriterTest.cs index a73f151e66..495910ae90 100644 --- a/com.unity.netcode.gameobjects/Tests/Editor/Serialization/BaseFastBufferReaderWriterTest.cs +++ b/com.unity.netcode.gameobjects/Tests/Editor/Serialization/BaseFastBufferReaderWriterTest.cs @@ -239,6 +239,10 @@ public void BaseTypeTest(Type testType, WriteType writeType) { RunTestWithWriteType(new Quaternion((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble()), writeType); } + else if (testType == typeof(Pose)) + { + RunTestWithWriteType(new Pose(new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble()), new Quaternion((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble())), writeType); + } else if (testType == typeof(Color)) { RunTestWithWriteType(new Color((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble()), writeType); @@ -544,6 +548,20 @@ void RunTypeTestLocal(T[] val, WriteType wt) where T : unmanaged (float) random.NextDouble(), (float) random.NextDouble()), }, writeType); } + else if (testType == typeof(Pose)) + { + RunTypeTestLocal(new[]{ + new Pose(new Vector3((float) random.NextDouble(), (float) random.NextDouble(), (float) random.NextDouble()), + new Quaternion((float) random.NextDouble(), (float) random.NextDouble(), + (float) random.NextDouble(), (float) random.NextDouble())), + new Pose(new Vector3((float) random.NextDouble(), (float) random.NextDouble(), (float) random.NextDouble()), + new Quaternion((float) random.NextDouble(), (float) random.NextDouble(), + (float) random.NextDouble(), (float) random.NextDouble())), + new Pose(new Vector3((float) random.NextDouble(), (float) random.NextDouble(), (float) random.NextDouble()), + new Quaternion((float) random.NextDouble(), (float) random.NextDouble(), + (float) random.NextDouble(), (float) random.NextDouble())), + }, writeType); + } else if (testType == typeof(Color)) { RunTypeTestLocal(new[]{ @@ -886,6 +904,20 @@ void RunTypeTestLocal(NativeArray val, WriteType wt) where T : unmanaged (float) random.NextDouble(), (float) random.NextDouble()), }, Allocator.Temp), writeType); } + else if (testType == typeof(Pose)) + { + RunTypeTestLocal(new NativeArray(new[]{ + new Pose(new Vector3((float) random.NextDouble(), (float) random.NextDouble(), (float) random.NextDouble()), + new Quaternion((float) random.NextDouble(), (float) random.NextDouble(), + (float) random.NextDouble(), (float) random.NextDouble())), + new Pose(new Vector3((float) random.NextDouble(), (float) random.NextDouble(), (float) random.NextDouble()), + new Quaternion((float) random.NextDouble(), (float) random.NextDouble(), + (float) random.NextDouble(), (float) random.NextDouble())), + new Pose(new Vector3((float) random.NextDouble(), (float) random.NextDouble(), (float) random.NextDouble()), + new Quaternion((float) random.NextDouble(), (float) random.NextDouble(), + (float) random.NextDouble(), (float) random.NextDouble())), + }, Allocator.Temp), writeType); + } else if (testType == typeof(Color)) { RunTypeTestLocal(new NativeArray(new[]{ @@ -1233,6 +1265,20 @@ void RunTypeTestLocal(NativeArray val, WriteType wt) where T : unmanaged (float) random.NextDouble(), (float) random.NextDouble()), }, Allocator.Temp), writeType); } + else if (testType == typeof(Pose)) + { + RunTypeTestLocal(new NativeArray(new[]{ + new Pose(new Vector3((float) random.NextDouble(), (float) random.NextDouble(), (float) random.NextDouble()), + new Quaternion((float) random.NextDouble(), (float) random.NextDouble(), + (float) random.NextDouble(), (float) random.NextDouble())), + new Pose(new Vector3((float) random.NextDouble(), (float) random.NextDouble(), (float) random.NextDouble()), + new Quaternion((float) random.NextDouble(), (float) random.NextDouble(), + (float) random.NextDouble(), (float) random.NextDouble())), + new Pose(new Vector3((float) random.NextDouble(), (float) random.NextDouble(), (float) random.NextDouble()), + new Quaternion((float) random.NextDouble(), (float) random.NextDouble(), + (float) random.NextDouble(), (float) random.NextDouble())), + }, Allocator.Temp), writeType); + } else if (testType == typeof(Color)) { RunTypeTestLocal(new NativeArray(new[]{ diff --git a/com.unity.netcode.gameobjects/Tests/Editor/Serialization/BytePackerTests.cs b/com.unity.netcode.gameobjects/Tests/Editor/Serialization/BytePackerTests.cs index 99e8582fba..395a49f217 100644 --- a/com.unity.netcode.gameobjects/Tests/Editor/Serialization/BytePackerTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Editor/Serialization/BytePackerTests.cs @@ -109,7 +109,7 @@ private unsafe void RunTypeTest(T value) where T : unmanaged object[] args = { reader, outVal }; method.Invoke(null, args); outVal = (T)args[1]; - Assert.AreEqual(value, outVal); + EqualityHelper.AreEqual(value, outVal); VerifyBytewiseEquality(value, outVal); } } @@ -555,7 +555,7 @@ public void TestPackingBasicTypes( typeof(long), typeof(ulong), typeof(bool), typeof(char), typeof(float), typeof(double), typeof(ByteEnum), typeof(SByteEnum), typeof(ShortEnum), typeof(UShortEnum), typeof(IntEnum), typeof(UIntEnum), typeof(LongEnum), typeof(ULongEnum), typeof(Vector2), typeof(Vector3), typeof(Vector4), - typeof(Quaternion), typeof(Color), typeof(Color32), typeof(Ray), typeof(Ray2D))] + typeof(Quaternion), typeof(Pose), typeof(Color), typeof(Color32), typeof(Ray), typeof(Ray2D))] Type testType, [Values] WriteType writeType) { @@ -758,6 +758,15 @@ public void TestPackingBasicTypes( RunTypeTest(v); } } + else if (testType == typeof(Pose)) + { + var v = new Pose(new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble()), + new Quaternion((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble())); + if (writeType == WriteType.WriteDirect) + { + RunTypeTest(v); + } + } else if (testType == typeof(Color)) { var v = new Color((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble()); diff --git a/com.unity.netcode.gameobjects/Tests/Editor/Serialization/FastBufferReaderTests.cs b/com.unity.netcode.gameobjects/Tests/Editor/Serialization/FastBufferReaderTests.cs index 2b4c70ebcb..3f8599b7f3 100644 --- a/com.unity.netcode.gameobjects/Tests/Editor/Serialization/FastBufferReaderTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Editor/Serialization/FastBufferReaderTests.cs @@ -490,7 +490,7 @@ private void VerifyArrayEquality(T[] value, T[] compareValue, int offset) whe for (var i = 0; i < value.Length; ++i) { - Assert.AreEqual(value[i], compareValue[i]); + EqualityHelper.AreEqual(value[i], compareValue[i]); } } @@ -500,7 +500,7 @@ private void VerifyArrayEquality(NativeArray value, NativeArray compare for (var i = 0; i < value.Length; ++i) { - Assert.AreEqual(value[i], compareValue[i]); + EqualityHelper.AreEqual(value[i], compareValue[i]); } } @@ -511,7 +511,7 @@ private void VerifyArrayEquality(NativeList value, NativeList compareVa for (var i = 0; i < value.Length; ++i) { - Assert.AreEqual(value[i], compareValue[i]); + EqualityHelper.AreEqual(value[i], compareValue[i]); } } #endif @@ -682,7 +682,7 @@ public void GivenFastBufferWriterContainingValue_WhenReadingUnmanagedType_ValueM typeof(long), typeof(ulong), typeof(bool), typeof(char), typeof(float), typeof(double), typeof(ByteEnum), typeof(SByteEnum), typeof(ShortEnum), typeof(UShortEnum), typeof(IntEnum), typeof(UIntEnum), typeof(LongEnum), typeof(ULongEnum), typeof(Vector2), typeof(Vector3), - typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4), typeof(Quaternion), typeof(Color), + typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4), typeof(Quaternion), typeof(Pose), typeof(Color), typeof(Color32), typeof(Ray), typeof(Ray2D), typeof(TestStruct))] Type testType, [Values] WriteType writeType) @@ -696,7 +696,7 @@ public void GivenFastBufferWriterContainingValue_WhenReadingArrayOfUnmanagedElem typeof(long), typeof(ulong), typeof(bool), typeof(char), typeof(float), typeof(double), typeof(ByteEnum), typeof(SByteEnum), typeof(ShortEnum), typeof(UShortEnum), typeof(IntEnum), typeof(UIntEnum), typeof(LongEnum), typeof(ULongEnum), typeof(Vector2), typeof(Vector3), - typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4), typeof(Quaternion), typeof(Color), + typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4), typeof(Quaternion), typeof(Pose), typeof(Color), typeof(Color32), typeof(Ray), typeof(Ray2D), typeof(TestStruct))] Type testType, [Values] WriteType writeType) @@ -710,7 +710,7 @@ public void GivenFastBufferWriterContainingValue_WhenReadingNativeArrayOfUnmanag typeof(long), typeof(ulong), typeof(bool), typeof(char), typeof(float), typeof(double), typeof(ByteEnum), typeof(SByteEnum), typeof(ShortEnum), typeof(UShortEnum), typeof(IntEnum), typeof(UIntEnum), typeof(LongEnum), typeof(ULongEnum), typeof(Vector2), typeof(Vector3), - typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4), typeof(Quaternion), typeof(Color), + typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4), typeof(Quaternion), typeof(Pose), typeof(Color), typeof(Color32), typeof(Ray), typeof(Ray2D), typeof(TestStruct))] Type testType, [Values] WriteType writeType) @@ -725,7 +725,7 @@ public void GivenFastBufferWriterContainingValue_WhenReadingNativeListOfUnmanage typeof(long), typeof(ulong), typeof(bool), typeof(char), typeof(float), typeof(double), typeof(ByteEnum), typeof(SByteEnum), typeof(ShortEnum), typeof(UShortEnum), typeof(IntEnum), typeof(UIntEnum), typeof(LongEnum), typeof(ULongEnum), typeof(Vector2), typeof(Vector3), - typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4), typeof(Quaternion), typeof(Color), + typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4), typeof(Quaternion), typeof(Pose), typeof(Color), typeof(Color32), typeof(Ray), typeof(Ray2D), typeof(TestStruct))] Type testType, [Values] WriteType writeType) diff --git a/com.unity.netcode.gameobjects/Tests/Editor/Serialization/FastBufferWriterTests.cs b/com.unity.netcode.gameobjects/Tests/Editor/Serialization/FastBufferWriterTests.cs index f658fcbcc4..40159a99c8 100644 --- a/com.unity.netcode.gameobjects/Tests/Editor/Serialization/FastBufferWriterTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Editor/Serialization/FastBufferWriterTests.cs @@ -39,7 +39,7 @@ private unsafe void VerifyBytewiseEquality(T value, byte[] underlyingArray, i private unsafe void VerifyTypedEquality(T value, byte* unsafePtr) where T : unmanaged { var checkValue = (T*)unsafePtr; - Assert.AreEqual(value, *checkValue); + EqualityHelper.AreEqual(value, *checkValue); } private void VerifyPositionAndLength(FastBufferWriter writer, int position, string failMessage = "") @@ -288,7 +288,7 @@ private unsafe void VerifyArrayEquality(T[] value, byte* unsafePtr, int offse var underlyingTArray = (T*)(unsafePtr + sizeof(int) + offset); for (var i = 0; i < value.Length; ++i) { - Assert.AreEqual(asTPointer[i], underlyingTArray[i]); + EqualityHelper.AreEqual(asTPointer[i], underlyingTArray[i]); } } } @@ -302,7 +302,7 @@ private unsafe void VerifyArrayEquality(NativeArray value, byte* unsafePtr var underlyingTArray = (T*)(unsafePtr + sizeof(int) + offset); for (var i = 0; i < value.Length; ++i) { - Assert.AreEqual(asTPointer[i], underlyingTArray[i]); + EqualityHelper.AreEqual(asTPointer[i], underlyingTArray[i]); } } @@ -316,7 +316,7 @@ private unsafe void VerifyArrayEquality(NativeList value, byte* unsafePtr, var underlyingTArray = (T*)(unsafePtr + sizeof(int) + offset); for (var i = 0; i < value.Length; ++i) { - Assert.AreEqual(asTPointer[i], underlyingTArray[i]); + EqualityHelper.AreEqual(asTPointer[i], underlyingTArray[i]); } } #endif @@ -460,7 +460,7 @@ public void WhenWritingUnmanagedType_ValueIsWrittenCorrectly( typeof(long), typeof(ulong), typeof(bool), typeof(char), typeof(float), typeof(double), typeof(ByteEnum), typeof(SByteEnum), typeof(ShortEnum), typeof(UShortEnum), typeof(IntEnum), typeof(UIntEnum), typeof(LongEnum), typeof(ULongEnum), typeof(Vector2), typeof(Vector3), - typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4), typeof(Quaternion), typeof(Color), + typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4), typeof(Quaternion), typeof(Pose), typeof(Color), typeof(Color32), typeof(Ray), typeof(Ray2D), typeof(TestStruct))] Type testType, [Values] WriteType writeType) @@ -474,7 +474,7 @@ public void WhenWritingArrayOfUnmanagedElementType_ArrayIsWrittenCorrectly( typeof(long), typeof(ulong), typeof(bool), typeof(char), typeof(float), typeof(double), typeof(ByteEnum), typeof(SByteEnum), typeof(ShortEnum), typeof(UShortEnum), typeof(IntEnum), typeof(UIntEnum), typeof(LongEnum), typeof(ULongEnum), typeof(Vector2), typeof(Vector3), - typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4), typeof(Quaternion), typeof(Color), + typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4), typeof(Quaternion), typeof(Pose), typeof(Color), typeof(Color32), typeof(Ray), typeof(Ray2D), typeof(TestStruct))] Type testType, [Values] WriteType writeType) @@ -488,7 +488,7 @@ public void WhenWritingNativeArrayOfUnmanagedElementType_NativeArrayIsWrittenCor typeof(long), typeof(ulong), typeof(bool), typeof(char), typeof(float), typeof(double), typeof(ByteEnum), typeof(SByteEnum), typeof(ShortEnum), typeof(UShortEnum), typeof(IntEnum), typeof(UIntEnum), typeof(LongEnum), typeof(ULongEnum), typeof(Vector2), typeof(Vector3), - typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4), typeof(Quaternion), typeof(Color), + typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4), typeof(Quaternion), typeof(Pose), typeof(Color), typeof(Color32), typeof(Ray), typeof(Ray2D), typeof(TestStruct))] Type testType, [Values] WriteType writeType) @@ -503,7 +503,7 @@ public void WhenWritingNativeListOfUnmanagedElementType_NativeListIsWrittenCorre typeof(long), typeof(ulong), typeof(bool), typeof(char), typeof(float), typeof(double), typeof(ByteEnum), typeof(SByteEnum), typeof(ShortEnum), typeof(UShortEnum), typeof(IntEnum), typeof(UIntEnum), typeof(LongEnum), typeof(ULongEnum), typeof(Vector2), typeof(Vector3), - typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4), typeof(Quaternion), typeof(Color), + typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4), typeof(Quaternion), typeof(Pose), typeof(Color), typeof(Color32), typeof(Ray), typeof(Ray2D), typeof(TestStruct))] Type testType, [Values] WriteType writeType) diff --git a/com.unity.netcode.gameobjects/Tests/Editor/TestHelpers.meta b/com.unity.netcode.gameobjects/Tests/Editor/TestHelpers.meta new file mode 100644 index 0000000000..2312b4e24b --- /dev/null +++ b/com.unity.netcode.gameobjects/Tests/Editor/TestHelpers.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 77a73db6d685d144380c22395267cf47 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.netcode.gameobjects/Tests/Editor/TestHelpers/EqualityHelper.cs b/com.unity.netcode.gameobjects/Tests/Editor/TestHelpers/EqualityHelper.cs new file mode 100644 index 0000000000..81fd0a9784 --- /dev/null +++ b/com.unity.netcode.gameobjects/Tests/Editor/TestHelpers/EqualityHelper.cs @@ -0,0 +1,27 @@ +using NUnit.Framework; +using UnityEngine; + +namespace Unity.Netcode.EditorTests +{ + public static class EqualityHelper + { + /// + /// Custom equal assertion, that fix the issue with Pose equality + /// See https://forum.unity.com/threads/pose-equality-not-implemented-in-accordance-with-quaterion.1484145/ + /// + /// + /// + /// + public static void AreEqual(T value, T compareValue) + { + if (value.GetType() == typeof(Pose)) { + object v = value; + object cv = compareValue; + Assert.AreEqual(((Pose)v).position, ((Pose)cv).position); + Assert.AreEqual(((Pose)v).rotation, ((Pose)cv).rotation); + } else { + Assert.AreEqual(value, compareValue); + } + } + } +} diff --git a/com.unity.netcode.gameobjects/Tests/Editor/TestHelpers/EqualityHelper.cs.meta b/com.unity.netcode.gameobjects/Tests/Editor/TestHelpers/EqualityHelper.cs.meta new file mode 100644 index 0000000000..b3bcce6f77 --- /dev/null +++ b/com.unity.netcode.gameobjects/Tests/Editor/TestHelpers/EqualityHelper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b9b656418b5aab2488fd646b8cdbbe75 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/Components/NetworkVariableTestComponent.cs b/com.unity.netcode.gameobjects/Tests/Runtime/Components/NetworkVariableTestComponent.cs index 468600f8b3..622bfae8f4 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/Components/NetworkVariableTestComponent.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/Components/NetworkVariableTestComponent.cs @@ -191,6 +191,7 @@ internal class NetworkVariableTestComponent : NetworkBehaviour private NetworkVariable m_NetworkVariableLong = new NetworkVariable(); private NetworkVariable m_NetworkVariableSByte = new NetworkVariable(); private NetworkVariable m_NetworkVariableQuaternion = new NetworkVariable(); + private NetworkVariable m_NetworkVariablePose = new NetworkVariable(); private NetworkVariable m_NetworkVariableShort = new NetworkVariable(); private NetworkVariable m_NetworkVariableVector4 = new NetworkVariable(); private NetworkVariable m_NetworkVariableVector3 = new NetworkVariable(); @@ -217,6 +218,7 @@ internal class NetworkVariableTestComponent : NetworkBehaviour public NetworkVariableHelper Long_Var; public NetworkVariableHelper Sbyte_Var; public NetworkVariableHelper Quaternion_Var; + public NetworkVariableHelper Pose_Var; public NetworkVariableHelper Short_Var; public NetworkVariableHelper Vector4_Var; public NetworkVariableHelper Vector3_Var; @@ -253,6 +255,7 @@ private void InitializeTest() m_NetworkVariableLong = new NetworkVariable(); m_NetworkVariableSByte = new NetworkVariable(); m_NetworkVariableQuaternion = new NetworkVariable(); + m_NetworkVariablePose = new NetworkVariable(); m_NetworkVariableShort = new NetworkVariable(); m_NetworkVariableVector4 = new NetworkVariable(); m_NetworkVariableVector3 = new NetworkVariable(); @@ -280,6 +283,7 @@ private void InitializeTest() m_NetworkVariableLong = new NetworkVariable(1); m_NetworkVariableSByte = new NetworkVariable(0); m_NetworkVariableQuaternion = new NetworkVariable(Quaternion.identity); + m_NetworkVariablePose = new NetworkVariable(Pose.identity); m_NetworkVariableShort = new NetworkVariable(256); m_NetworkVariableVector4 = new NetworkVariable(new Vector4(1, 1, 1, 1)); m_NetworkVariableVector3 = new NetworkVariable(new Vector3(1, 1, 1)); @@ -312,6 +316,7 @@ private void InitializeTest() Long_Var = new NetworkVariableHelper(m_NetworkVariableLong); Sbyte_Var = new NetworkVariableHelper(m_NetworkVariableSByte); Quaternion_Var = new NetworkVariableHelper(m_NetworkVariableQuaternion); + Pose_Var = new NetworkVariableHelper(m_NetworkVariablePose); Short_Var = new NetworkVariableHelper(m_NetworkVariableShort); Vector4_Var = new NetworkVariableHelper(m_NetworkVariableVector4); Vector3_Var = new NetworkVariableHelper(m_NetworkVariableVector3); @@ -376,6 +381,13 @@ public void AssertAllValuesAreCorrect() Assert.AreEqual(100, m_NetworkVariableQuaternion.Value.x); Assert.AreEqual(100, m_NetworkVariableQuaternion.Value.y); Assert.AreEqual(100, m_NetworkVariableQuaternion.Value.z); + Assert.AreEqual(100, m_NetworkVariablePose.Value.position.x); + Assert.AreEqual(100, m_NetworkVariablePose.Value.position.y); + Assert.AreEqual(100, m_NetworkVariablePose.Value.position.z); + Assert.AreEqual(100, m_NetworkVariablePose.Value.rotation.w); + Assert.AreEqual(100, m_NetworkVariablePose.Value.rotation.x); + Assert.AreEqual(100, m_NetworkVariablePose.Value.rotation.y); + Assert.AreEqual(100, m_NetworkVariablePose.Value.rotation.z); Assert.AreEqual(short.MaxValue, m_NetworkVariableShort.Value); Assert.AreEqual(1000, m_NetworkVariableVector4.Value.w); Assert.AreEqual(1000, m_NetworkVariableVector4.Value.x); @@ -435,6 +447,7 @@ private void Update() m_NetworkVariableLong.Value = 100000; m_NetworkVariableSByte.Value = -127; m_NetworkVariableQuaternion.Value = new Quaternion(100, 100, 100, 100); + m_NetworkVariablePose.Value = new Pose(new Vector3(100, 100, 100), new Quaternion(100, 100, 100, 100)); m_NetworkVariableShort.Value = short.MaxValue; m_NetworkVariableVector4.Value = new Vector4(1000, 1000, 1000, 1000); m_NetworkVariableVector3.Value = new Vector3(1000, 1000, 1000); diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/NetworkVariableTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/NetworkVariableTests.cs index 1dec25d89e..3e6484658f 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/NetworkVariableTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/NetworkVariableTests.cs @@ -276,6 +276,12 @@ public class NetVarILPPClassForTests : NetworkBehaviour #if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT public NetworkVariable> QuaternionListVar; #endif + public NetworkVariable PoseVar; + public NetworkVariable> PoseArrayVar; +#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT + public NetworkVariable> PoseListVar; +#endif + public NetworkVariable ColorVar; public NetworkVariable> ColorArrayVar; #if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT @@ -1625,7 +1631,7 @@ public void WhenSerializingAndDeserializingValueTypeNetworkVariables_ValuesAreSe typeof(long), typeof(ulong), typeof(bool), typeof(char), typeof(float), typeof(double), typeof(ByteEnum), typeof(SByteEnum), typeof(ShortEnum), typeof(UShortEnum), typeof(IntEnum), typeof(UIntEnum), typeof(LongEnum), typeof(ULongEnum), typeof(Vector2), typeof(Vector3), - typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4), typeof(Quaternion), typeof(Color), + typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4), typeof(Quaternion), typeof(Pose), typeof(Color), typeof(Color32), typeof(Ray), typeof(Ray2D), typeof(NetworkVariableTestStruct), typeof(FixedString32Bytes))] Type testType) { @@ -1745,6 +1751,12 @@ public void WhenSerializingAndDeserializingValueTypeNetworkVariables_ValuesAreSe new Quaternion(5, 10, 15, 20), new Quaternion(25, 30, 35, 40)); } + else if (testType == typeof(Pose)) + { + TestValueType( + new Pose(new Vector3(5, 10, 15), new Quaternion(20, 25, 30, 35)), + new Pose(new Vector3(40, 45, 50), new Quaternion(55, 60, 65, 70))); + } else if (testType == typeof(Color)) { TestValueType( @@ -1786,7 +1798,7 @@ public void WhenSerializingAndDeserializingValueTypeNativeArrayNetworkVariables_ typeof(long), typeof(ulong), typeof(bool), typeof(char), typeof(float), typeof(double), typeof(ByteEnum), typeof(SByteEnum), typeof(ShortEnum), typeof(UShortEnum), typeof(IntEnum), typeof(UIntEnum), typeof(LongEnum), typeof(ULongEnum), typeof(Vector2), typeof(Vector3), - typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4), typeof(Quaternion), typeof(Color), + typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4), typeof(Quaternion), typeof(Pose), typeof(Color), typeof(Color32), typeof(Ray), typeof(Ray2D), typeof(NetworkVariableTestStruct), typeof(FixedString32Bytes))] Type testType) { @@ -1946,6 +1958,12 @@ public void WhenSerializingAndDeserializingValueTypeNativeArrayNetworkVariables_ new NativeArray(new Quaternion[] { new Quaternion(5, 10, 15, 20), new Quaternion(25, 30, 35, 40) }, Allocator.Temp), new NativeArray(new Quaternion[] { new Quaternion(45, 50, 55, 60), new Quaternion(65, 70, 75, 80), new Quaternion(85, 90, 95, 100) }, Allocator.Temp)); } + else if (testType == typeof(Pose)) + { + TestValueTypeNativeArray( + new NativeArray(new Pose[] { new Pose(new Vector3(5, 10, 15), new Quaternion(20, 25, 30, 35)), new Pose(new Vector3(40, 45, 50), new Quaternion(55, 60, 65, 70)) }, Allocator.Temp), + new NativeArray(new Pose[] { new Pose(new Vector3(75, 80, 85), new Quaternion(90, 95, 100, 105)), new Pose(new Vector3(110, 115, 120), new Quaternion(125, 130, 135, 140)), new Pose(new Vector3(145, 150, 155), new Quaternion(160, 165, 170, 175)) }, Allocator.Temp)); + } else if (testType == typeof(Color)) { TestValueTypeNativeArray( @@ -2028,7 +2046,7 @@ public void WhenSerializingAndDeserializingValueTypeNativeListNetworkVariables_V typeof(long), typeof(ulong), typeof(bool), typeof(char), typeof(float), typeof(double), typeof(ByteEnum), typeof(SByteEnum), typeof(ShortEnum), typeof(UShortEnum), typeof(IntEnum), typeof(UIntEnum), typeof(LongEnum), typeof(ULongEnum), typeof(Vector2), typeof(Vector3), - typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4), typeof(Quaternion), typeof(Color), + typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4), typeof(Quaternion), typeof(Pose), typeof(Color), typeof(Color32), typeof(Ray), typeof(Ray2D), typeof(NetworkVariableTestStruct), typeof(FixedString32Bytes))] Type testType) { @@ -2188,6 +2206,12 @@ public void WhenSerializingAndDeserializingValueTypeNativeListNetworkVariables_V new NativeList(Allocator.Temp) { new Quaternion(5, 10, 15, 20), new Quaternion(25, 30, 35, 40) }, new NativeList(Allocator.Temp) { new Quaternion(45, 50, 55, 60), new Quaternion(65, 70, 75, 80), new Quaternion(85, 90, 95, 100) }); } + else if (testType == typeof(Pose)) + { + TestValueTypeNativeList( + new NativeList(Allocator.Temp) { new Pose(new Vector3(5, 10, 15), new Quaternion(20, 25, 30, 35)), new Pose(new Vector3(40, 45, 50), new Quaternion(55, 60, 65, 70)) }, + new NativeList(Allocator.Temp) { new Pose(new Vector3(75, 80, 85), new Quaternion(90, 95, 100, 105)), new Pose(new Vector3(110, 115, 120), new Quaternion(125, 130, 135, 140)), new Pose(new Vector3(145, 150, 155), new Quaternion(160, 165, 170, 175)) }); + } else if (testType == typeof(Color)) { TestValueTypeNativeList( diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/RpcTypeSerializationTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/RpcTypeSerializationTests.cs index 9d09d67772..f6a6368905 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/RpcTypeSerializationTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/RpcTypeSerializationTests.cs @@ -702,6 +702,32 @@ public void QuaternionNativeListClientRpc(NativeList value) } #endif + [ClientRpc] + public void PoseClientRpc(Pose value) + { + OnReceived(value); + } + + [ClientRpc] + public void PoseArrayClientRpc(Pose[] value) + { + OnReceived(value); + } + + [ClientRpc] + public void PoseNativeArrayClientRpc(NativeArray value) + { + OnReceived(value); + } + +#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT + [ClientRpc] + public void PoseNativeListClientRpc(NativeList value) + { + OnReceived(value); + } +#endif + [ClientRpc] public void ColorClientRpc(Color value) { @@ -1105,7 +1131,7 @@ public IEnumerator WhenSendingAValueTypeOverAnRpc_ValuesAreSerializedCorrectly( typeof(long), typeof(ulong), typeof(bool), typeof(char), typeof(float), typeof(double), typeof(ByteEnum), typeof(SByteEnum), typeof(ShortEnum), typeof(UShortEnum), typeof(IntEnum), typeof(UIntEnum), typeof(LongEnum), typeof(ULongEnum), typeof(Vector2), typeof(Vector3), - typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4), typeof(Quaternion), typeof(Color), + typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4), typeof(Quaternion), typeof(Pose), typeof(Color), typeof(Color32), typeof(Ray), typeof(Ray2D), typeof(NetworkVariableTestStruct), typeof(FixedString32Bytes))] Type testType) { @@ -1225,6 +1251,12 @@ public IEnumerator WhenSendingAValueTypeOverAnRpc_ValuesAreSerializedCorrectly( new Quaternion(5, 10, 15, 20), new Quaternion(25, 30, 35, 40)); } + else if (testType == typeof(Pose)) + { + yield return TestValueType( + new Pose(new Vector3(5, 10, 15), new Quaternion(20, 25, 30, 35)), + new Pose(new Vector3(40, 45, 50), new Quaternion(55, 60, 65, 70))); + } else if (testType == typeof(Color)) { yield return TestValueType( @@ -1266,7 +1298,7 @@ public IEnumerator WhenSendingAnArrayOfValueTypesOverAnRpc_ValuesAreSerializedCo typeof(long), typeof(ulong), typeof(bool), typeof(char), typeof(float), typeof(double), typeof(ByteEnum), typeof(SByteEnum), typeof(ShortEnum), typeof(UShortEnum), typeof(IntEnum), typeof(UIntEnum), typeof(LongEnum), typeof(ULongEnum), typeof(Vector2), typeof(Vector3), - typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4), typeof(Quaternion), typeof(Color), + typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4), typeof(Quaternion), typeof(Pose), typeof(Color), typeof(Color32), typeof(Ray), typeof(Ray2D), typeof(NetworkVariableTestStruct), typeof(FixedString32Bytes))] Type testType) { @@ -1426,6 +1458,12 @@ public IEnumerator WhenSendingAnArrayOfValueTypesOverAnRpc_ValuesAreSerializedCo new Quaternion[] { new Quaternion(5, 10, 15, 20), new Quaternion(25, 30, 35, 40) }, new Quaternion[] { new Quaternion(45, 50, 55, 60), new Quaternion(65, 70, 75, 80), new Quaternion(85, 90, 95, 100) }); } + else if (testType == typeof(Pose)) + { + yield return TestValueTypeArray( + new Pose[] { new Pose(new Vector3(5, 10, 15), new Quaternion(20, 25, 30, 35)), new Pose(new Vector3(40, 45, 50), new Quaternion(55, 60, 65, 70)) }, + new Pose[] { new Pose(new Vector3(75, 80, 85), new Quaternion(90, 95, 100, 105)), new Pose(new Vector3(110, 115, 120), new Quaternion(125, 130, 135, 140)), new Pose(new Vector3(145, 150, 155), new Quaternion(160, 165, 170, 175)) }); + } else if (testType == typeof(Color)) { yield return TestValueTypeArray( @@ -1507,7 +1545,7 @@ public IEnumerator WhenSendingANativeArrayOfValueTypesOverAnRpc_ValuesAreSeriali typeof(long), typeof(ulong), typeof(bool), typeof(char), typeof(float), typeof(double), typeof(ByteEnum), typeof(SByteEnum), typeof(ShortEnum), typeof(UShortEnum), typeof(IntEnum), typeof(UIntEnum), typeof(LongEnum), typeof(ULongEnum), typeof(Vector2), typeof(Vector3), - typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4), typeof(Quaternion), typeof(Color), + typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4), typeof(Quaternion), typeof(Pose), typeof(Color), typeof(Color32), typeof(Ray), typeof(Ray2D), typeof(NetworkVariableTestStruct), typeof(FixedString32Bytes))] Type testType) { @@ -1667,6 +1705,12 @@ public IEnumerator WhenSendingANativeArrayOfValueTypesOverAnRpc_ValuesAreSeriali new NativeArray(new Quaternion[] { new Quaternion(5, 10, 15, 20), new Quaternion(25, 30, 35, 40) }, Allocator.Persistent), new NativeArray(new Quaternion[] { new Quaternion(45, 50, 55, 60), new Quaternion(65, 70, 75, 80), new Quaternion(85, 90, 95, 100) }, Allocator.Persistent)); } + else if (testType == typeof(Pose)) + { + yield return TestValueTypeNativeArray( + new NativeArray(new Pose[] { new Pose(new Vector3(5, 10, 15), new Quaternion(20, 25, 30, 35)), new Pose(new Vector3(40, 45, 50), new Quaternion(55, 60, 65, 70)) }, Allocator.Persistent), + new NativeArray(new Pose[] { new Pose(new Vector3(75, 80, 85), new Quaternion(90, 95, 100, 105)), new Pose(new Vector3(110, 115, 120), new Quaternion(125, 130, 135, 140)), new Pose(new Vector3(145, 150, 155), new Quaternion(160, 165, 170, 175)) }, Allocator.Persistent)); + } else if (testType == typeof(Color)) { yield return TestValueTypeNativeArray( @@ -1749,7 +1793,7 @@ public IEnumerator WhenSendingANativeListOfValueTypesOverAnRpc_ValuesAreSerializ typeof(long), typeof(ulong), typeof(bool), typeof(char), typeof(float), typeof(double), typeof(ByteEnum), typeof(SByteEnum), typeof(ShortEnum), typeof(UShortEnum), typeof(IntEnum), typeof(UIntEnum), typeof(LongEnum), typeof(ULongEnum), typeof(Vector2), typeof(Vector3), - typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4), typeof(Quaternion), typeof(Color), + typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4), typeof(Quaternion), typeof(Pose), typeof(Color), typeof(Color32), typeof(Ray), typeof(Ray2D), typeof(NetworkVariableTestStruct), typeof(FixedString32Bytes))] Type testType) { @@ -1909,6 +1953,12 @@ public IEnumerator WhenSendingANativeListOfValueTypesOverAnRpc_ValuesAreSerializ new NativeList(Allocator.Persistent) { new Quaternion(5, 10, 15, 20), new Quaternion(25, 30, 35, 40) }, new NativeList(Allocator.Persistent) { new Quaternion(45, 50, 55, 60), new Quaternion(65, 70, 75, 80), new Quaternion(85, 90, 95, 100) }); } + else if (testType == typeof(Pose)) + { + yield return TestValueTypeNativeList( + new NativeList(Allocator.Persistent) { new Pose(new Vector3(5, 10, 15), new Quaternion(20, 25, 30, 35)), new Pose(new Vector3(40, 45, 50), new Quaternion(55, 60, 65, 70)) }, + new NativeList(Allocator.Persistent) { new Pose(new Vector3(75, 80, 85), new Quaternion(90, 95, 100, 105)), new Pose(new Vector3(110, 115, 120), new Quaternion(125, 130, 135, 140)), new Pose(new Vector3(145, 150, 155), new Quaternion(160, 165, 170, 175)) }); + } else if (testType == typeof(Color)) { yield return TestValueTypeNativeList(