diff --git a/com.unity.netcode.gameobjects/CHANGELOG.md b/com.unity.netcode.gameobjects/CHANGELOG.md
index 68af4702af..319ef4d7e0 100644
--- a/com.unity.netcode.gameobjects/CHANGELOG.md
+++ b/com.unity.netcode.gameobjects/CHANGELOG.md
@@ -10,6 +10,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
### Added
+- Added serializer for `Pose` (#3540)
- Added mappings between `ClientId` and `TransportId`. (#3515)
- Added `SinglePlayerTransport` that provides the ability to start as a host for a single player network session. (#3475)
- When using UnityTransport >=2.4 and Unity >= 6000.1.0a1, SetConnectionData will accept a fully qualified hostname instead of an IP as a connect address on the client side. (#3440)
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 3d56d5136c..5a6d46023d 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 faf4c960fa..155f32eff6 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
///
@@ -553,6 +565,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 b064f2dbce..a823c154cf 100644
--- a/com.unity.netcode.gameobjects/Runtime/Serialization/BytePacker.cs
+++ b/com.unity.netcode.gameobjects/Runtime/Serialization/BytePacker.cs
@@ -259,6 +259,18 @@ 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);
+ WriteValuePacked(writer, pose.rotation);
+ }
+
///
/// 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 2c84fff991..310ba46c6b 100644
--- a/com.unity.netcode.gameobjects/Runtime/Serialization/ByteUnpacker.cs
+++ b/com.unity.netcode.gameobjects/Runtime/Serialization/ByteUnpacker.cs
@@ -278,6 +278,19 @@ 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)
+ {
+ ReadValuePacked(reader, out Vector3 position);
+ ReadValuePacked(reader, out Quaternion rotation);
+ pose = new Pose(position, rotation);
+ }
+
///
/// 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 7f87e02240..c0a19be924 100644
--- a/com.unity.netcode.gameobjects/Runtime/Serialization/FastBufferReader.cs
+++ b/com.unity.netcode.gameobjects/Runtime/Serialization/FastBufferReader.cs
@@ -1328,6 +1328,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
///
@@ -1505,6 +1519,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 b22c0782e8..037f9a6a47 100644
--- a/com.unity.netcode.gameobjects/Runtime/Serialization/FastBufferWriter.cs
+++ b/com.unity.netcode.gameobjects/Runtime/Serialization/FastBufferWriter.cs
@@ -1491,6 +1491,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
///
@@ -1667,6 +1681,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 2ec4f7b95d..676d09cf69 100644
--- a/com.unity.netcode.gameobjects/Runtime/Serialization/IReaderWriter.cs
+++ b/com.unity.netcode.gameobjects/Runtime/Serialization/IReaderWriter.cs
@@ -231,6 +231,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
///
@@ -530,6 +542,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..69faab600e 100644
--- a/com.unity.netcode.gameobjects/Tests/Editor/Serialization/BytePackerTests.cs
+++ b/com.unity.netcode.gameobjects/Tests/Editor/Serialization/BytePackerTests.cs
@@ -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 17d0c979d9..afd2712700 100644
--- a/com.unity.netcode.gameobjects/Tests/Editor/Serialization/FastBufferReaderTests.cs
+++ b/com.unity.netcode.gameobjects/Tests/Editor/Serialization/FastBufferReaderTests.cs
@@ -460,6 +460,7 @@ protected override unsafe void RunTypeTest(T valueToTest)
}
}
}
+
protected override unsafe void RunTypeTestSafe(T valueToTest)
{
var writeSize = FastBufferWriter.GetWriteSize(valueToTest);
@@ -682,7 +683,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 +697,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 +711,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 +726,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 5967d49488..11e218a82e 100644
--- a/com.unity.netcode.gameobjects/Tests/Editor/Serialization/FastBufferWriterTests.cs
+++ b/com.unity.netcode.gameobjects/Tests/Editor/Serialization/FastBufferWriterTests.cs
@@ -463,7 +463,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)
@@ -477,7 +477,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)
@@ -491,7 +491,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)
@@ -506,7 +506,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/Runtime/Components/NetworkVariableTestComponent.cs b/com.unity.netcode.gameobjects/Tests/Runtime/Components/NetworkVariableTestComponent.cs
index 468600f8b3..7d54ee5ecd 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(new Pose(new Vector3(1, 1, 1), Quaternion.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 f9995caba4..c7dcf21816 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(
@@ -1851,7 +1857,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)
{
@@ -2011,6 +2017,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(
@@ -2187,7 +2199,7 @@ public void WhenSerializingAndDeserializingVeryLargeValueTypeNativeArrayNetworkV
[Values(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint),
typeof(long), typeof(ulong), typeof(bool), typeof(char), typeof(float), typeof(double),
typeof(Vector2), typeof(Vector3), typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4),
- typeof(Quaternion), typeof(Color), typeof(Color32), typeof(Ray), typeof(Ray2D),
+ typeof(Quaternion), typeof(Pose), typeof(Color), typeof(Color32), typeof(Ray), typeof(Ray2D),
typeof(NetworkVariableTestStruct), typeof(FixedString32Bytes))]
Type testType)
{
@@ -2311,6 +2323,14 @@ public void WhenSerializingAndDeserializingVeryLargeValueTypeNativeArrayNetworkV
TestValueTypeNativeArray(original, changed);
TestValueTypeNativeArray(original2, changed2);
}
+ else if (testType == typeof(Pose))
+ {
+ (var original, var original2, var changed, var changed2) = GetArarys(
+ (rand) => new Pose(new Vector3((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble()), new Quaternion((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble()))
+ );
+ TestValueTypeNativeArray(original, changed);
+ TestValueTypeNativeArray(original2, changed2);
+ }
else if (testType == typeof(Color))
{
(var original, var original2, var changed, var changed2) = GetArarys(
@@ -2653,7 +2673,7 @@ public void WhenSerializingAndDeserializingVeryLargeListNetworkVariables_ValuesA
[Values(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint),
typeof(long), typeof(ulong), typeof(bool), typeof(char), typeof(float), typeof(double),
typeof(Vector2), typeof(Vector3), typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4),
- typeof(Quaternion), typeof(Color), typeof(Color32), typeof(Ray), typeof(Ray2D),
+ typeof(Quaternion), typeof(Pose), typeof(Color), typeof(Color32), typeof(Ray), typeof(Ray2D),
typeof(NetworkVariableTestClass), typeof(FixedString32Bytes))]
Type testType)
{
@@ -2777,6 +2797,14 @@ public void WhenSerializingAndDeserializingVeryLargeListNetworkVariables_ValuesA
TestList(original, changed);
TestList(original2, changed2);
}
+ else if (testType == typeof(Pose))
+ {
+ (var original, var original2, var changed, var changed2) = GetLists(
+ (rand) => new Pose(new Vector3((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble()), new Quaternion((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble()))
+ );
+ TestList(original, changed);
+ TestList(original2, changed2);
+ }
else if (testType == typeof(Color))
{
(var original, var original2, var changed, var changed2) = GetLists(
@@ -2840,7 +2868,7 @@ public void WhenSerializingAndDeserializingVeryLargeHashSetNetworkVariables_Valu
[Values(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint),
typeof(long), typeof(ulong), typeof(bool), typeof(char), typeof(float), typeof(double),
typeof(Vector2), typeof(Vector3), typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4),
- typeof(Quaternion), typeof(HashableNetworkVariableTestClass), typeof(FixedString32Bytes))]
+ typeof(Quaternion), typeof(Pose), typeof(HashableNetworkVariableTestClass), typeof(FixedString32Bytes))]
Type testType)
{
if (testType == typeof(byte))
@@ -2963,6 +2991,14 @@ public void WhenSerializingAndDeserializingVeryLargeHashSetNetworkVariables_Valu
TestHashSet(original, changed);
TestHashSet(original2, changed2);
}
+ else if (testType == typeof(Pose))
+ {
+ (var original, var original2, var changed, var changed2) = GetHashSets(
+ (rand) => new Pose(new Vector3((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble()), new Quaternion((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble()))
+ );
+ TestHashSet(original, changed);
+ TestHashSet(original2, changed2);
+ }
else if (testType == typeof(Color))
{
(var original, var original2, var changed, var changed2) = GetHashSets(
@@ -2997,7 +3033,7 @@ public void WhenSerializingAndDeserializingVeryLargeDictionaryNetworkVariables_V
[Values(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint),
typeof(long), typeof(ulong), typeof(bool), typeof(char), typeof(float), typeof(double),
typeof(Vector2), typeof(Vector3), typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4),
- typeof(Quaternion), typeof(HashMapValClass), typeof(FixedString32Bytes))]
+ typeof(Quaternion), typeof(Pose), typeof(HashMapValClass), typeof(FixedString32Bytes))]
Type valType)
{
if (valType == typeof(byte))
@@ -3522,6 +3558,35 @@ public void WhenSerializingAndDeserializingVeryLargeDictionaryNetworkVariables_V
TestDictionary(original2, changed2);
}
}
+ else if (valType == typeof(Pose))
+ {
+ if (keyType == typeof(byte))
+ {
+ (var original, var original2, var changed, var changed2) = GetDictionaries(RandGenBytes, (rand) => new Pose(new Vector3((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble()), new Quaternion((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble())));
+ TestDictionary(original, changed);
+ TestDictionary(original2, changed2);
+
+ }
+ else if (keyType == typeof(ulong))
+ {
+ (var original, var original2, var changed, var changed2) = GetDictionaries(RandGenBytes, (rand) => new Pose(new Vector3((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble()), new Quaternion((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble())));
+ TestDictionary(original, changed);
+ TestDictionary(original2, changed2);
+ }
+ else if (keyType == typeof(Vector2))
+ {
+ (var original, var original2, var changed, var changed2) = GetDictionaries((rand) => new Vector2((float)rand.NextDouble(), (float)rand.NextDouble()), (rand) => new Pose(new Vector3((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble()), new Quaternion((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble())));
+ TestDictionary(original, changed);
+ TestDictionary(original2, changed2);
+
+ }
+ else if (keyType == typeof(HashMapKeyClass))
+ {
+ (var original, var original2, var changed, var changed2) = GetDictionaries((rand) => new HashMapKeyClass { Data = RandGenBytes(rand) }, (rand) => new Quaternion((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble()));
+ TestDictionary(original, changed);
+ TestDictionary(original2, changed2);
+ }
+ }
else if (valType == typeof(HashMapValClass))
{
if (keyType == typeof(byte))
@@ -3591,7 +3656,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)
{
@@ -3751,6 +3816,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(
@@ -4115,7 +4186,7 @@ public void WhenSerializingAndDeserializingVeryLargeValueTypeNativeListNetworkVa
[Values(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint),
typeof(long), typeof(ulong), typeof(bool), typeof(char), typeof(float), typeof(double),
typeof(Vector2), typeof(Vector3), typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4),
- typeof(Quaternion), typeof(Color), typeof(Color32), typeof(Ray), typeof(Ray2D),
+ typeof(Quaternion), typeof(Pose),typeof(Color), typeof(Color32), typeof(Ray), typeof(Ray2D),
typeof(NetworkVariableTestStruct), typeof(FixedString32Bytes))]
Type testType)
{
@@ -4239,6 +4310,14 @@ public void WhenSerializingAndDeserializingVeryLargeValueTypeNativeListNetworkVa
TestValueTypeNativeList(original, changed);
TestValueTypeNativeList(original2, changed2);
}
+ else if (testType == typeof(Pose))
+ {
+ (var original, var original2, var changed, var changed2) = GetNativeLists(
+ (rand) => new Pose(new Vector3((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble()), new Quaternion((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble()))
+ );
+ TestValueTypeNativeList(original, changed);
+ TestValueTypeNativeList(original2, changed2);
+ }
else if (testType == typeof(Color))
{
(var original, var original2, var changed, var changed2) = GetNativeLists(
@@ -4298,7 +4377,7 @@ public void WhenSerializingAndDeserializingVeryLargeValueTypeNativeHashSetNetwor
[Values(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint),
typeof(long), typeof(ulong), typeof(bool), typeof(char), typeof(float), typeof(double),
typeof(Vector2), typeof(Vector3), typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4),
- typeof(Quaternion), typeof(HashableNetworkVariableTestStruct), typeof(FixedString32Bytes))]
+ typeof(Quaternion), typeof(Pose), typeof(HashableNetworkVariableTestStruct), typeof(FixedString32Bytes))]
Type testType)
{
if (testType == typeof(byte))
@@ -4421,6 +4500,14 @@ public void WhenSerializingAndDeserializingVeryLargeValueTypeNativeHashSetNetwor
TestValueTypeNativeHashSet(original, changed);
TestValueTypeNativeHashSet(original2, changed2);
}
+ else if (testType == typeof(Pose))
+ {
+ (var original, var original2, var changed, var changed2) = GetNativeHashSets(
+ (rand) => new Pose(new Vector3((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble()), new Quaternion((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble()))
+ );
+ TestValueTypeNativeHashSet(original, changed);
+ TestValueTypeNativeHashSet(original2, changed2);
+ }
else if (testType == typeof(Color))
{
(var original, var original2, var changed, var changed2) = GetNativeHashSets(
@@ -4451,7 +4538,7 @@ public void WhenSerializingAndDeserializingVeryLargeValueTypeNativeHashMapNetwor
[Values(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint),
typeof(long), typeof(ulong), typeof(bool), typeof(char), typeof(float), typeof(double),
typeof(Vector2), typeof(Vector3), typeof(Vector2Int), typeof(Vector3Int), typeof(Vector4),
- typeof(Quaternion), typeof(HashMapValStruct), typeof(FixedString32Bytes))]
+ typeof(Quaternion), typeof(Pose), typeof(HashMapValStruct), typeof(FixedString32Bytes))]
Type valType)
{
if (valType == typeof(byte))
@@ -4976,6 +5063,35 @@ public void WhenSerializingAndDeserializingVeryLargeValueTypeNativeHashMapNetwor
TestValueTypeNativeHashMap(original2, changed2);
}
}
+ else if (valType == typeof(Pose))
+ {
+ if (keyType == typeof(byte))
+ {
+ (var original, var original2, var changed, var changed2) = GetMaps(RandGenBytes, (rand) => new Pose(new Vector3((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble()), new Quaternion((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble())));
+ TestValueTypeNativeHashMap(original, changed);
+ TestValueTypeNativeHashMap(original2, changed2);
+
+ }
+ else if (keyType == typeof(ulong))
+ {
+ (var original, var original2, var changed, var changed2) = GetMaps(RandGenBytes, (rand) => new Pose(new Vector3((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble()), new Quaternion((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble())));
+ TestValueTypeNativeHashMap(original, changed);
+ TestValueTypeNativeHashMap(original2, changed2);
+ }
+ else if (keyType == typeof(Vector2))
+ {
+ (var original, var original2, var changed, var changed2) = GetMaps((rand) => new Vector2((float)rand.NextDouble(), (float)rand.NextDouble()), (rand) => new Pose(new Vector3((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble()), new Quaternion((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble())));
+ TestValueTypeNativeHashMap(original, changed);
+ TestValueTypeNativeHashMap(original2, changed2);
+
+ }
+ else if (keyType == typeof(HashMapKeyStruct))
+ {
+ (var original, var original2, var changed, var changed2) = GetMaps(RandGenBytes, (rand) => new Pose(new Vector3((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble()), new Quaternion((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble())));
+ TestValueTypeNativeHashMap(original, changed);
+ TestValueTypeNativeHashMap(original2, changed2);
+ }
+ }
else if (valType == typeof(HashMapValStruct))
{
if (keyType == typeof(byte))
diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/NetworkVariableTestsHelperTypes.cs b/com.unity.netcode.gameobjects/Tests/Runtime/NetworkVariableTestsHelperTypes.cs
index ab0f65d022..e98259bf40 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 4758a23b6d..b11d168c13 100644
--- a/com.unity.netcode.gameobjects/Tests/Runtime/RpcTypeSerializationTests.cs
+++ b/com.unity.netcode.gameobjects/Tests/Runtime/RpcTypeSerializationTests.cs
@@ -705,6 +705,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)
{
@@ -1108,7 +1134,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)
{
@@ -1228,6 +1254,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(
@@ -1269,7 +1301,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)
{
@@ -1429,6 +1461,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(
@@ -1511,7 +1549,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)
{
@@ -1671,6 +1709,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(
@@ -1753,7 +1797,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)
{
@@ -1913,6 +1957,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(
diff --git a/pvpExceptions.json b/pvpExceptions.json
index 03a2cee707..2ea47b4862 100644
--- a/pvpExceptions.json
+++ b/pvpExceptions.json
@@ -2094,6 +2094,16 @@
"Unity.Netcode.RuntimeTests.NetVarILPPClassForTests: ULongQuaternionDictionaryVar: undocumented",
"Unity.Netcode.RuntimeTests.NetVarILPPClassForTests: Vector2QuaternionDictionaryVar: undocumented",
"Unity.Netcode.RuntimeTests.NetVarILPPClassForTests: HashMapKeyClassQuaternionDictionaryVar: undocumented",
+ "Unity.Netcode.RuntimeTests.NetVarILPPClassForTests: PoseVar: undocumented",
+ "Unity.Netcode.RuntimeTests.NetVarILPPClassForTests: PoseArrayVar: undocumented",
+ "Unity.Netcode.RuntimeTests.NetVarILPPClassForTests: PoseManagedListVar: undocumented",
+ "Unity.Netcode.RuntimeTests.NetVarILPPClassForTests: PoseManagedHashSetVar: undocumented",
+ "Unity.Netcode.RuntimeTests.NetVarILPPClassForTests: BytePoseDictionaryVar: undocumented",
+ "Unity.Netcode.RuntimeTests.NetVarILPPClassForTests: ULongPoseDictionaryVar: undocumented",
+ "Unity.Netcode.RuntimeTests.NetVarILPPClassForTests: Vector2PoseDictionaryVar: undocumented",
+ "Unity.Netcode.RuntimeTests.NetVarILPPClassForTests: HashMapKeyClassPoseDictionaryVar: undocumented",
+ "Unity.Netcode.RuntimeTests.RpcTypeSerializationTests.RpcTestNB: void PoseClientRpc(Pose): undocumented",
+ "Unity.Netcode.RuntimeTests.RpcTypeSerializationTests.RpcTestNB: void PoseArrayClientRpc(Pose[]): undocumented",
"Unity.Netcode.RuntimeTests.NetVarILPPClassForTests: ColorVar: undocumented",
"Unity.Netcode.RuntimeTests.NetVarILPPClassForTests: ColorArrayVar: undocumented",
"Unity.Netcode.RuntimeTests.NetVarILPPClassForTests: ColorManagedListVar: undocumented",
@@ -2371,6 +2381,9 @@
"Unity.Netcode.RuntimeTests.RpcTypeSerializationTests.RpcTestNB: void QuaternionClientRpc(Quaternion): undocumented",
"Unity.Netcode.RuntimeTests.RpcTypeSerializationTests.RpcTestNB: void QuaternionArrayClientRpc(Quaternion[]): undocumented",
"Unity.Netcode.RuntimeTests.RpcTypeSerializationTests.RpcTestNB: void QuaternionNativeArrayClientRpc(NativeArray): undocumented",
+ "Unity.Netcode.RuntimeTests.RpcTypeSerializationTests.RpcTestNB: void PoseClientRpc(Pose): undocumented",
+ "Unity.Netcode.RuntimeTests.RpcTypeSerializationTests.RpcTestNB: void PoseArrayClientRpc(Pose[]): undocumented",
+ "Unity.Netcode.RuntimeTests.RpcTypeSerializationTests.RpcTestNB: void PoseNativeArrayClientRpc(NativeArray): undocumented",
"Unity.Netcode.RuntimeTests.RpcTypeSerializationTests.RpcTestNB: void ColorClientRpc(Color): undocumented",
"Unity.Netcode.RuntimeTests.RpcTypeSerializationTests.RpcTestNB: void ColorArrayClientRpc(Color[]): undocumented",
"Unity.Netcode.RuntimeTests.RpcTypeSerializationTests.RpcTestNB: void ColorNativeArrayClientRpc(NativeArray): undocumented",