Example #1
0
        public void RpcIsCalledWithAbstractNetworkBehaviourParameter()
        {
            // spawn with owner
            CreateNetworkedAndSpawn(out GameObject _, out NetworkIdentity _, out AbstractNetworkBehaviourClientRpcBehaviour hostBehaviour, NetworkServer.localConnection);

            // spawn clientrpc parameter targets
            CreateNetworkedAndSpawn(out GameObject _, out NetworkIdentity wolfIdentity, out AbstractNetworkBehaviourClientRpcBehaviour.MockWolf wolf, NetworkServer.localConnection);
            CreateNetworkedAndSpawn(out GameObject _, out NetworkIdentity zombieIdentity, out AbstractNetworkBehaviourClientRpcBehaviour.MockZombie zombie, NetworkServer.localConnection);

            AbstractNetworkBehaviourClientRpcBehaviour.MockMonsterBase currentMonster = null;

            int callCount = 0;

            hostBehaviour.onSendMonsterBase += incomingMonster =>
            {
                callCount++;
                Assert.That(incomingMonster, Is.EqualTo(currentMonster));
            };

            currentMonster = wolf;
            hostBehaviour.RpcSendMonster(currentMonster);
            ProcessMessages();
            Assert.That(callCount, Is.EqualTo(1));

            currentMonster = zombie;
            hostBehaviour.RpcSendMonster(currentMonster);
            ProcessMessages();
            Assert.That(callCount, Is.EqualTo(2));
        }
Example #2
0
        public void RpcIsCalledWithAbstractNetworkBehaviourParameter()
        {
            // spawn with owner
            CreateNetworkedAndSpawn(out _, out _, out AbstractNetworkBehaviourClientRpcBehaviour serverComponent,
                                    out _, out _, out AbstractNetworkBehaviourClientRpcBehaviour clientComponent,
                                    connectionToClient);

            // spawn clientrpc parameter targets
            CreateNetworkedAndSpawn(out _, out _, out AbstractNetworkBehaviourClientRpcBehaviour.MockWolf wolf,
                                    out _, out _, out _,
                                    connectionToClient);
            CreateNetworkedAndSpawn(out _, out _, out AbstractNetworkBehaviourClientRpcBehaviour.MockZombie zombie,
                                    out _, out _, out _,
                                    connectionToClient);

            AbstractNetworkBehaviourClientRpcBehaviour.MockMonsterBase currentMonster = null;

            int called = 0;

            clientComponent.onSendMonsterBase += incomingMonster =>
            {
                called++;
                Assert.That(incomingMonster, Is.EqualTo(currentMonster));
            };

            currentMonster = wolf;
            serverComponent.RpcSendMonster(currentMonster);
            ProcessMessages();
            Assert.That(called, Is.EqualTo(1));

            currentMonster = zombie;
            serverComponent.RpcSendMonster(currentMonster);
            ProcessMessages();
            Assert.That(called, Is.EqualTo(2));
        }