Exemple #1
0
        public void NetworkBehaviourHook_HookCalledWhenSyncingChangedValue(bool intialState)
        {
            NetworkBehaviourHookBehaviour serverObject = CreateObject <NetworkBehaviourHookBehaviour>();
            NetworkBehaviourHookBehaviour clientObject = CreateObject <NetworkBehaviourHookBehaviour>();

            NetworkBehaviourHookBehaviour clientValue = null;
            NetworkBehaviourHookBehaviour serverValue = CreateNetworkIdentity(2033).gameObject.AddComponent <NetworkBehaviourHookBehaviour>();

            serverObject.value = serverValue;
            clientObject.value = clientValue;

            int callCount = 0;

            clientObject.HookCalled += (oldValue, newValue) =>
            {
                callCount++;
                Assert.That(oldValue, Is.EqualTo(clientValue));
                Assert.That(newValue, Is.EqualTo(serverValue));
            };

            bool written = SyncToClient(serverObject, clientObject, intialState);

            Assert.IsTrue(written);
            Assert.That(callCount, Is.EqualTo(1));
        }
Exemple #2
0
        public void NetworkBehaviourHook_HookCalledWhenSyncingChangedValue(bool intialState)
        {
            CreateNetworked(out GameObject _, out NetworkIdentity _, out NetworkBehaviourHookBehaviour serverObject);
            CreateNetworked(out GameObject _, out NetworkIdentity _, out NetworkBehaviourHookBehaviour clientObject);

            NetworkBehaviourHookBehaviour clientValue = null;

            CreateNetworked(out GameObject _, out NetworkIdentity serverIdentity, out NetworkBehaviourHookBehaviour serverValue);
            serverIdentity.netId = 2033;
            NetworkIdentity.spawned[serverIdentity.netId] = serverIdentity;

            serverObject.value = serverValue;
            clientObject.value = clientValue;

            int callCount = 0;

            clientObject.HookCalled += (oldValue, newValue) =>
            {
                callCount++;
                Assert.That(oldValue, Is.EqualTo(clientValue));
                Assert.That(newValue, Is.EqualTo(serverValue));
            };

            bool written = SyncToClient(serverObject, clientObject, intialState);

            Assert.IsTrue(written);
            Assert.That(callCount, Is.EqualTo(1));
        }
Exemple #3
0
 void OnValueChanged(NetworkBehaviourHookBehaviour oldValue, NetworkBehaviourHookBehaviour newValue)
 {
     HookCalled.Invoke(oldValue, newValue);
 }