diff --git a/com.unity.netcode.gameobjects/CHANGELOG.md b/com.unity.netcode.gameobjects/CHANGELOG.md index 6b4470e084..acf98740dd 100644 --- a/com.unity.netcode.gameobjects/CHANGELOG.md +++ b/com.unity.netcode.gameobjects/CHANGELOG.md @@ -8,6 +8,10 @@ Additional documentation and release notes are available at [Multiplayer Documen ## [Unreleased] +### Added + +- Added serializer for `Pose` (#2675) + ### Fixed - Removed anoying warnings when using NetworkVariable in offline mode. (#2279) diff --git a/com.unity.netcode.gameobjects/Editor/CodeGen/CodeGenHelpers.cs b/com.unity.netcode.gameobjects/Editor/CodeGen/CodeGenHelpers.cs index 75387fa8db..8d29e112f0 100644 --- a/com.unity.netcode.gameobjects/Editor/CodeGen/CodeGenHelpers.cs +++ b/com.unity.netcode.gameobjects/Editor/CodeGen/CodeGenHelpers.cs @@ -44,6 +44,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; @@ -308,6 +309,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 1734d02311..189a553593 100644 --- a/com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs +++ b/com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs @@ -562,6 +562,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 8adcc98790..cdc60bdc12 100644 --- a/com.unity.netcode.gameobjects/Runtime/Serialization/FastBufferReader.cs +++ b/com.unity.netcode.gameobjects/Runtime/Serialization/FastBufferReader.cs @@ -1279,6 +1279,20 @@ internal void ReadValueSafeInPlace(ref NativeHashMap val [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 /// @@ -1456,6 +1470,26 @@ internal void ReadValueSafeInPlace(ref NativeHashMap val [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 aa50ad6a9a..dd23a0c49b 100644 --- a/com.unity.netcode.gameobjects/Runtime/Serialization/FastBufferWriter.cs +++ b/com.unity.netcode.gameobjects/Runtime/Serialization/FastBufferWriter.cs @@ -1466,6 +1466,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 /// @@ -1642,6 +1656,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..c3737476b9 100644 --- a/com.unity.netcode.gameobjects/Tests/Editor/Serialization/FastBufferReaderTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Editor/Serialization/FastBufferReaderTests.cs @@ -456,7 +456,7 @@ protected override unsafe void RunTypeTest(T valueToTest) { Assert.IsTrue(reader.TryBeginRead(FastBufferWriter.GetWriteSize())); RunReadMethod(nameof(FastBufferReader.ReadValue), reader, out T result); - Assert.AreEqual(valueToTest, result); + EqualityHelper.AreEqual(valueToTest, result); } } } @@ -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 2029fa1e05..e8763f1108 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/NetworkVariableTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/NetworkVariableTests.cs @@ -1689,7 +1689,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) { @@ -1809,6 +1809,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( @@ -1850,7 +1856,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) { @@ -2010,6 +2016,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( @@ -3574,7 +3586,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) { @@ -3734,6 +3746,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/NetworkVariableTestsHelperTypes.cs b/com.unity.netcode.gameobjects/Tests/Runtime/NetworkVariableTestsHelperTypes.cs index 67d54cd20d..800fd26c08 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/NetworkVariableTestsHelperTypes.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/NetworkVariableTestsHelperTypes.cs @@ -802,6 +802,23 @@ public class NetVarILPPClassForTests : NetworkBehaviour public NetworkVariable> Vector2QuaternionDictionaryVar; public NetworkVariable> HashMapKeyClassQuaternionDictionaryVar; + public NetworkVariable PoseVar; + public NetworkVariable> PoseArrayVar; + public NetworkVariable> PoseManagedListVar; + public NetworkVariable> PoseManagedHashSetVar; +#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT + public NetworkVariable> PoseListVar; + public NetworkVariable> PoseHashSetVar; + public NetworkVariable> BytePoseHashMapVar; + public NetworkVariable> ULongPoseHashMapVar; + public NetworkVariable> Vector2PoseHashMapVar; + public NetworkVariable> HashMapKeyStructPoseHashMapVar; +#endif + public NetworkVariable> BytePoseDictionaryVar; + public NetworkVariable> ULongPoseDictionaryVar; + public NetworkVariable> Vector2PoseDictionaryVar; + public NetworkVariable> HashMapKeyClassPoseDictionaryVar; + public NetworkVariable ColorVar; public NetworkVariable> ColorArrayVar; public NetworkVariable> ColorManagedListVar; diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/RpcTypeSerializationTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/RpcTypeSerializationTests.cs index 6016779cb1..78c239df0e 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/RpcTypeSerializationTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/RpcTypeSerializationTests.cs @@ -704,6 +704,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) { @@ -1107,7 +1133,7 @@ public void 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) { @@ -1227,6 +1253,12 @@ public void WhenSendingAValueTypeOverAnRpc_ValuesAreSerializedCorrectly( 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( @@ -1268,7 +1300,7 @@ public void WhenSendingAnArrayOfValueTypesOverAnRpc_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) { @@ -1428,6 +1460,12 @@ public void WhenSendingAnArrayOfValueTypesOverAnRpc_ValuesAreSerializedCorrectly 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)) + { + 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)) { TestValueTypeArray( @@ -1509,7 +1547,7 @@ public void WhenSendingANativeArrayOfValueTypesOverAnRpc_ValuesAreSerializedCorr 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) { @@ -1669,6 +1707,12 @@ public void WhenSendingANativeArrayOfValueTypesOverAnRpc_ValuesAreSerializedCorr 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)) + { + 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)) { TestValueTypeNativeArray( @@ -1751,7 +1795,7 @@ public void WhenSendingANativeListOfValueTypesOverAnRpc_ValuesAreSerializedCorre 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) { @@ -1911,6 +1955,12 @@ public void WhenSendingANativeListOfValueTypesOverAnRpc_ValuesAreSerializedCorre 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)) + { + 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)) { TestValueTypeNativeList(