public void SyncsBehaviour(bool initialState) { SyncVarNetworkBehaviour serverObject = CreateObject <SyncVarNetworkBehaviour>(); SyncVarNetworkBehaviour clientObject = CreateObject <SyncVarNetworkBehaviour>(); SyncVarNetworkBehaviour serverValue = CreateNetworkIdentity(2046).gameObject.AddComponent <SyncVarNetworkBehaviour>(); serverObject.value = serverValue; clientObject.value = null; bool written = SyncToClient(serverObject, clientObject, initialState); Assert.IsTrue(written); Assert.That(clientObject.value, Is.EqualTo(serverValue)); }
public void SyncsMultipleBehaviour(bool initialState) { SyncVarNetworkBehaviour serverObject = CreateObject <SyncVarNetworkBehaviour>(); SyncVarNetworkBehaviour clientObject = CreateObject <SyncVarNetworkBehaviour>(); NetworkIdentity identity = CreateNetworkIdentity(2046); SyncVarNetworkBehaviour behaviour1 = identity.gameObject.AddComponent <SyncVarNetworkBehaviour>(); SyncVarNetworkBehaviour behaviour2 = identity.gameObject.AddComponent <SyncVarNetworkBehaviour>(); // create array/set indices _ = identity.NetworkBehaviours; int index1 = behaviour1.ComponentIndex; int index2 = behaviour2.ComponentIndex; // check components of same type have different indexes Assert.That(index1, Is.Not.EqualTo(index2)); // check behaviour 1 can be synced serverObject.value = behaviour1; clientObject.value = null; bool written1 = SyncToClient(serverObject, clientObject, initialState); Assert.IsTrue(written1); Assert.That(clientObject.value, Is.EqualTo(behaviour1)); // check that behaviour 2 can be synced serverObject.value = behaviour2; clientObject.value = null; bool written2 = SyncToClient(serverObject, clientObject, initialState); Assert.IsTrue(written2); Assert.That(clientObject.value, Is.EqualTo(behaviour2)); }