mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
NetworkBehaviourTests: SerializeAndDeserializeObjectsAll
This commit is contained in:
parent
2ff53580ba
commit
d5b7802ae3
@ -1466,6 +1466,35 @@ public void DirtyObjectBits()
|
|||||||
cleanList.Add(43);
|
cleanList.Add(43);
|
||||||
Assert.That(comp.DirtyObjectBits(), Is.EqualTo(0b11));
|
Assert.That(comp.DirtyObjectBits(), Is.EqualTo(0b11));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void SerializeAndDeserializeObjectsAll()
|
||||||
|
{
|
||||||
|
// we need a component that exposes InitSyncObject so we can add some
|
||||||
|
NetworkBehaviourInitSyncObjectExposed comp = gameObject.AddComponent<NetworkBehaviourInitSyncObjectExposed>();
|
||||||
|
|
||||||
|
// add a synclist
|
||||||
|
SyncListInt list = new SyncListInt();
|
||||||
|
list.Add(42);
|
||||||
|
list.Add(43);
|
||||||
|
Assert.That(list.IsDirty, Is.True);
|
||||||
|
comp.InitSyncObjectExposed(list);
|
||||||
|
|
||||||
|
// serialize it
|
||||||
|
NetworkWriter writer = new NetworkWriter();
|
||||||
|
comp.SerializeObjectsAll(writer);
|
||||||
|
|
||||||
|
// clear original list
|
||||||
|
list.Clear();
|
||||||
|
Assert.That(list.Count, Is.EqualTo(0));
|
||||||
|
|
||||||
|
// deserialize it
|
||||||
|
NetworkReader reader = new NetworkReader(writer.ToArray());
|
||||||
|
comp.DeSerializeObjectsAll(reader);
|
||||||
|
Assert.That(list.Count, Is.EqualTo(2));
|
||||||
|
Assert.That(list[0], Is.EqualTo(42));
|
||||||
|
Assert.That(list[1], Is.EqualTo(43));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// we need to inherit from networkbehaviour to test protected functions
|
// we need to inherit from networkbehaviour to test protected functions
|
||||||
|
Loading…
Reference in New Issue
Block a user