NetworkIdentityTests: ClearAllComponentsDirtyBits

This commit is contained in:
vis2k 2020-03-02 11:14:27 +01:00
parent f9fdca3598
commit e43ed3e09d

View File

@ -1036,5 +1036,38 @@ public void ClearDirtyComponentsDirtyBits()
// clean up
GameObject.DestroyImmediate(gameObject);
}
[Test]
public void ClearAllComponentsDirtyBits()
{
// create a networkidentity and add some components
GameObject gameObject = new GameObject();
NetworkIdentity identity = gameObject.AddComponent<NetworkIdentity>();
OnStartClientTestNetworkBehaviour compA = gameObject.AddComponent<OnStartClientTestNetworkBehaviour>();
OnStartClientTestNetworkBehaviour compB = gameObject.AddComponent<OnStartClientTestNetworkBehaviour>();
// set syncintervals so one is always dirty, one is never dirty
compA.syncInterval = 0;
compB.syncInterval = Mathf.Infinity;
// set components dirty bits
compA.SetDirtyBit(0x0001);
compB.SetDirtyBit(0x1001);
Assert.That(compA.IsDirty(), Is.True); // dirty because interval reached and mask != 0
Assert.That(compB.IsDirty(), Is.False); // not dirty because syncinterval not reached
// call identity.ClearAllComponentsDirtyBits
identity.ClearAllComponentsDirtyBits();
Assert.That(compA.IsDirty(), Is.False); // should be cleared now
Assert.That(compB.IsDirty(), Is.False); // should be cleared now
// set compB syncinterval to 0 to check if the masks were cleared
// (if they weren't, then it would still be dirty now)
compB.syncInterval = 0;
Assert.That(compB.IsDirty(), Is.False);
// clean up
GameObject.DestroyImmediate(gameObject);
}
}
}