This commit is contained in:
vis2k 2022-04-01 23:44:27 +08:00
parent 3d471db938
commit bb17920791

View File

@ -34,6 +34,11 @@ class SyncVarNetworkBehaviour : NetworkBehaviour
[SyncVar] [SyncVar]
public SyncVarNetworkBehaviour value; public SyncVarNetworkBehaviour value;
} }
class SyncVarSetByRef : NetworkBehaviour
{
[SyncVar]
public int value;
}
class SyncVarAbstractNetworkBehaviour : NetworkBehaviour class SyncVarAbstractNetworkBehaviour : NetworkBehaviour
{ {
public abstract class MockMonsterBase : NetworkBehaviour public abstract class MockMonsterBase : NetworkBehaviour
@ -420,5 +425,22 @@ public void TestSyncingAbstractNetworkBehaviour()
Assert.That(clientBehaviour.monster1, Is.EqualTo(serverBehaviour.monster1), "Data should be synchronized"); Assert.That(clientBehaviour.monster1, Is.EqualTo(serverBehaviour.monster1), "Data should be synchronized");
Assert.That(clientBehaviour.monster2, Is.EqualTo(serverBehaviour.monster2), "Data should be synchronized"); Assert.That(clientBehaviour.monster2, Is.EqualTo(serverBehaviour.monster2), "Data should be synchronized");
} }
// test to prevent https://github.com/vis2k/Mirror/issues/3129
[Test]
public void SyncsIfSetByRef()
{
CreateNetworkedAndSpawn(
out _, out _, out SyncVarSetByRef serverObject,
out _, out _, out SyncVarSetByRef clientObject);
// set it by ref on the server
void Setter(out int value) => value = 42;
Setter(out serverObject.value);
// should sync to client
ProcessMessages();
Assert.That(clientObject.value, Is.EqualTo(42));
}
} }
} }