mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-17 18:40:33 +00:00
more tests
This commit is contained in:
parent
e9ef72fcdf
commit
f9c47d7e91
@ -516,5 +516,57 @@ public void SerializeServer_ObserversMode_ServerToClient_ReliableOnly()
|
|||||||
Assert.That(ownerWriterUnreliableDelta.Position, Is.EqualTo(0));
|
Assert.That(ownerWriterUnreliableDelta.Position, Is.EqualTo(0));
|
||||||
Assert.That(observersWriterUnreliableDelta.Position, Is.EqualTo(0));
|
Assert.That(observersWriterUnreliableDelta.Position, Is.EqualTo(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void SerializeServer_ObserversMode_ServerToClient_UnreliableOnly()
|
||||||
|
{
|
||||||
|
CreateNetworked(out GameObject _, out NetworkIdentity identity,
|
||||||
|
out SyncVarTest1NetworkBehaviour comp1,
|
||||||
|
out SyncVarTest2NetworkBehaviour comp2);
|
||||||
|
|
||||||
|
// one Reliable, one Unreliable component
|
||||||
|
comp1.syncMethod = SyncMethod.Reliable;
|
||||||
|
comp2.syncMethod = SyncMethod.Unreliable;
|
||||||
|
|
||||||
|
// pretend to be owned
|
||||||
|
identity.isOwned = true;
|
||||||
|
comp1.syncMode = comp2.syncMode = SyncMode.Observers;
|
||||||
|
comp1.syncInterval = comp2.syncInterval = 0;
|
||||||
|
|
||||||
|
// set to CLIENT with some unique values
|
||||||
|
// and set connection to server to pretend we are the owner.
|
||||||
|
comp1.syncDirection = comp2.syncDirection = SyncDirection.ServerToClient;
|
||||||
|
// comp1.SetValue(11); // Reliable component doesn't change this time
|
||||||
|
comp2.SetValue("22"); // modify with helper function to avoid #3525
|
||||||
|
|
||||||
|
// initial: should still write for owner AND observers
|
||||||
|
identity.SerializeServer_Spawn(ownerWriterReliable, observersWriterReliable);
|
||||||
|
Debug.Log("initial ownerWriter: " + ownerWriterReliable);
|
||||||
|
Debug.Log("initial observerWriter: " + observersWriterReliable);
|
||||||
|
Assert.That(ownerWriterReliable.Position, Is.GreaterThan(0));
|
||||||
|
Assert.That(observersWriterReliable.Position, Is.GreaterThan(0));
|
||||||
|
|
||||||
|
// delta: should write something for all
|
||||||
|
// comp1.SetValue(33); // Reliable component doesn't change this time
|
||||||
|
comp2.SetValue("44"); // modify with helper function to avoid #3525
|
||||||
|
ownerWriterReliable.Position = 0;
|
||||||
|
observersWriterReliable.Position = 0;
|
||||||
|
identity.SerializeServer_Broadcast(
|
||||||
|
ownerWriterReliable, observersWriterReliable,
|
||||||
|
ownerWriterUnreliableBaseline, observersWriterUnreliableBaseline,
|
||||||
|
ownerWriterUnreliableDelta, observersWriterUnreliableDelta,
|
||||||
|
false);
|
||||||
|
Debug.Log("delta ownerWriter: " + ownerWriterReliable);
|
||||||
|
Debug.Log("delta observersWriter: " + observersWriterReliable);
|
||||||
|
|
||||||
|
Assert.That(ownerWriterReliable.Position, Is.EqualTo(0));
|
||||||
|
Assert.That(observersWriterReliable.Position, Is.EqualTo(0));
|
||||||
|
|
||||||
|
Assert.That(ownerWriterUnreliableBaseline.Position, Is.GreaterThan(0));
|
||||||
|
Assert.That(observersWriterUnreliableBaseline.Position, Is.GreaterThan(0));
|
||||||
|
|
||||||
|
Assert.That(ownerWriterUnreliableDelta.Position, Is.GreaterThan(0));
|
||||||
|
Assert.That(observersWriterUnreliableDelta.Position, Is.GreaterThan(0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,6 +133,10 @@ public class SyncVarTest1NetworkBehaviour : NetworkBehaviour
|
|||||||
public class SyncVarTest2NetworkBehaviour : NetworkBehaviour
|
public class SyncVarTest2NetworkBehaviour : NetworkBehaviour
|
||||||
{
|
{
|
||||||
[SyncVar] public string value;
|
[SyncVar] public string value;
|
||||||
|
|
||||||
|
// function to modify the [SyncVar] from other assemblies.
|
||||||
|
// workaround for https://github.com/MirrorNetworking/Mirror/issues/3525
|
||||||
|
public void SetValue(string s) => value = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
[AddComponentMenu("")]
|
[AddComponentMenu("")]
|
||||||
|
Loading…
Reference in New Issue
Block a user