NetworkTransform.SerializeIntoWriterTest

This commit is contained in:
vis2k 2020-01-20 11:02:11 +01:00
parent 875f19e030
commit 15c77c6926
3 changed files with 40 additions and 1 deletions

View File

@ -16,6 +16,7 @@
// * Only way for smooth movement is to use a fixed movement speed during
// interpolation. interpolation over time is never that good.
//
using System.ComponentModel;
using UnityEngine;
namespace Mirror
@ -76,7 +77,8 @@ public class DataPoint
float lastClientSendTime;
// serialization is needed by OnSerialize and by manual sending from authority
static void SerializeIntoWriter(NetworkWriter writer, Vector3 position, Quaternion rotation, Compression compressRotation, Vector3 scale)
[EditorBrowsable(EditorBrowsableState.Never)] // public only for tests
public static void SerializeIntoWriter(NetworkWriter writer, Vector3 position, Quaternion rotation, Compression compressRotation, Vector3 scale)
{
// serialize position
writer.WriteVector3(position);

View File

@ -0,0 +1,26 @@
using System;
using NUnit.Framework;
using UnityEngine;
namespace Mirror.Tests
{
[TestFixture]
public class NetworkTransformTest
{
[Test]
public void SerializeIntoWriterTest()
{
NetworkWriter writer = new NetworkWriter();
Vector3 position = new Vector3(1, 2, 3);
Quaternion rotation = new Quaternion(0.1f, 0.2f, 0.3f, 0.4f);
Vector3 scale = new Vector3(0.5f, 0.6f, 0.7f);
// Compression.None
NetworkTransformBase.SerializeIntoWriter(writer, position, rotation, NetworkTransformBase.Compression.None, scale);
NetworkReader reader = new NetworkReader(writer.ToArray());
Assert.That(reader.ReadVector3(), Is.EqualTo(position));
Assert.That(reader.ReadVector3(), Is.EqualTo(rotation.eulerAngles));
Assert.That(reader.ReadVector3(), Is.EqualTo(scale));
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3114c5bb742fe41c09ec88e90ac29ef4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: