mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
NetworkBehaviourTests: SetSyncVarNetworkIdentityZeroNetId
This commit is contained in:
parent
abcecf1eaf
commit
b81a48ff36
@ -1219,6 +1219,46 @@ public void SetSyncVarNetworkIdentityNull()
|
||||
// clean up
|
||||
GameObject.DestroyImmediate(go);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SetSyncVarNetworkIdentityZeroNetId()
|
||||
{
|
||||
// add test component
|
||||
NetworkBehaviourSetSyncVarNetworkIdentityComponent comp = gameObject.AddComponent<NetworkBehaviourSetSyncVarNetworkIdentityComponent>();
|
||||
comp.syncInterval = 0; // for isDirty check
|
||||
|
||||
// set some existing NI+netId first to check if it is going to be
|
||||
// overwritten
|
||||
GameObject go = new GameObject();
|
||||
NetworkIdentity ni = go.AddComponent<NetworkIdentity>();
|
||||
comp.test = ni;
|
||||
comp.testNetId = 43;
|
||||
|
||||
// create test GO with networkidentity and zero netid
|
||||
GameObject test = new GameObject();
|
||||
NetworkIdentity testNi = test.AddComponent<NetworkIdentity>();
|
||||
Assert.That(testNi.netId, Is.EqualTo(0));
|
||||
|
||||
// set the NetworkIdentity SyncVar to 'test' GO with zero netId.
|
||||
// -> the way it currently works is that it sets netId to 0, but
|
||||
// it DOES set gameObjectField to the GameObject without the
|
||||
// NetworkIdentity, instead of setting it to null because it's
|
||||
// seemingly invalid.
|
||||
// -> there might be a deeper reason why UNET did that. perhaps for
|
||||
// cases where we assign a GameObject before the network was
|
||||
// fully started and has no netId or networkidentity yet etc.
|
||||
// => it works, so let's keep it for now
|
||||
Assert.That(comp.IsDirty(), Is.False);
|
||||
LogAssert.Expect(LogType.Warning, "SetSyncVarNetworkIdentity NetworkIdentity " + testNi + " has a zero netId. Maybe it is not spawned yet?");
|
||||
comp.SetSyncVarNetworkIdentityExposed(testNi, 1ul);
|
||||
Assert.That(comp.test, Is.EqualTo(testNi));
|
||||
Assert.That(comp.testNetId, Is.EqualTo(0));
|
||||
Assert.That(comp.IsDirty(), Is.True);
|
||||
|
||||
// clean up
|
||||
GameObject.DestroyImmediate(test);
|
||||
GameObject.DestroyImmediate(go);
|
||||
}
|
||||
}
|
||||
|
||||
// we need to inherit from networkbehaviour to test protected functions
|
||||
|
Loading…
Reference in New Issue
Block a user