Skip to content

Commit fe8e6c1

Browse files
committed
serialize the Vector3 and Quaternion directly
1 parent 0269285 commit fe8e6c1

File tree

5 files changed

+8
-18
lines changed

5 files changed

+8
-18
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
1010

1111
### Added
1212

13+
- Added serializer for `Pose` (#2675)
1314
- Added mappings between `ClientId` and `TransportId`. (#3515)
1415
- Added `SinglePlayerTransport` that provides the ability to start as a host for a single player network session. (#3475)
1516
- 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)
@@ -34,7 +35,6 @@ Additional documentation and release notes are available at [Multiplayer Documen
3435
- Added `NetworkManager.OnPreShutdown` which is called before the NetworkManager cleans up and shuts down. (#3358)
3536
- Added `FastBufferReader(ArraySegment<byte> buffer, Allocator copyAllocator)` constructor that uses the `ArraySegment.Offset` as the `FastBufferReader` offset and the `ArraySegment.Count` as the `FastBufferReader` length. (#3320)
3637
- Added `FastBufferReader(ArraySegment<byte> buffer, Allocator copyAllocator, int length = -1)` constructor that uses the `ArraySegment.Offset` as the `FastBufferReader` offset. (#3320)
37-
- Added serializer for `Pose` (#2675)
3838

3939
### Fixed
4040

com.unity.netcode.gameobjects/Runtime/Serialization/BytePacker.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,8 @@ public static void WriteValuePacked(FastBufferWriter writer, Quaternion rotation
267267
[MethodImpl(MethodImplOptions.AggressiveInlining)]
268268
public static void WriteValuePacked(FastBufferWriter writer, Pose pose)
269269
{
270-
WriteValuePacked(writer, pose.position.x);
271-
WriteValuePacked(writer, pose.position.y);
272-
WriteValuePacked(writer, pose.position.z);
273-
WriteValuePacked(writer, pose.rotation.x);
274-
WriteValuePacked(writer, pose.rotation.y);
275-
WriteValuePacked(writer, pose.rotation.z);
276-
WriteValuePacked(writer, pose.rotation.w);
270+
WriteValuePacked(writer, pose.position);
271+
WriteValuePacked(writer, pose.rotation);
277272
}
278273

279274
/// <summary>

com.unity.netcode.gameobjects/Runtime/Serialization/ByteUnpacker.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -286,14 +286,9 @@ public static void ReadValuePacked(FastBufferReader reader, out Quaternion rotat
286286
[MethodImpl(MethodImplOptions.AggressiveInlining)]
287287
public static void ReadValuePacked(FastBufferReader reader, out Pose pose)
288288
{
289-
pose = new Pose();
290-
ReadValuePacked(reader, out pose.position.x);
291-
ReadValuePacked(reader, out pose.position.y);
292-
ReadValuePacked(reader, out pose.position.z);
293-
ReadValuePacked(reader, out pose.rotation.x);
294-
ReadValuePacked(reader, out pose.rotation.y);
295-
ReadValuePacked(reader, out pose.rotation.z);
296-
ReadValuePacked(reader, out pose.rotation.w);
289+
ReadValuePacked(reader, out Vector3 position);
290+
ReadValuePacked(reader, out Quaternion rotation);
291+
pose = new Pose(position, rotation);
297292
}
298293

299294
/// <summary>

com.unity.netcode.gameobjects/Tests/Editor/Serialization/FastBufferReaderTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ protected override unsafe void RunTypeTest<T>(T valueToTest)
460460
}
461461
}
462462
}
463-
463+
464464
protected override unsafe void RunTypeTestSafe<T>(T valueToTest)
465465
{
466466
var writeSize = FastBufferWriter.GetWriteSize(valueToTest);

com.unity.netcode.gameobjects/Tests/Runtime/Components/NetworkVariableTestComponent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ private void InitializeTest()
283283
m_NetworkVariableLong = new NetworkVariable<long>(1);
284284
m_NetworkVariableSByte = new NetworkVariable<sbyte>(0);
285285
m_NetworkVariableQuaternion = new NetworkVariable<Quaternion>(Quaternion.identity);
286-
m_NetworkVariablePose = new NetworkVariable<Pose>(Pose.identity);
286+
m_NetworkVariablePose = new NetworkVariable<Pose>(new Pose(new Vector3(1, 1, 1), Quaternion.identity));
287287
m_NetworkVariableShort = new NetworkVariable<short>(256);
288288
m_NetworkVariableVector4 = new NetworkVariable<Vector4>(new Vector4(1, 1, 1, 1));
289289
m_NetworkVariableVector3 = new NetworkVariable<Vector3>(new Vector3(1, 1, 1));

0 commit comments

Comments
 (0)