예제 #1
0
        public IEnumerator OnDestroySpawnHandlerTest() => UniTask.ToCoroutine(async() =>
        {
            spawnDelegateTestCalled = 0;
            var guid                 = Guid.NewGuid();
            var gameObject           = new GameObject();
            NetworkIdentity identity = gameObject.AddComponent <NetworkIdentity>();
            identity.AssetId         = guid;

            UnSpawnDelegate unspawnDelegate = Substitute.For <UnSpawnDelegate>();

            clientObjectManager.RegisterSpawnHandler(guid, SpawnDelegateTest, unspawnDelegate);
            clientObjectManager.RegisterPrefab(identity, guid);
            serverObjectManager.SendSpawnMessage(identity, connectionToClient);

            await AsyncUtil.WaitUntilWithTimeout(() => spawnDelegateTestCalled != 0);

            clientObjectManager.OnObjectDestroy(new ObjectDestroyMessage
            {
                netId = identity.NetId
            });
            unspawnDelegate.Received().Invoke(Arg.Any <NetworkIdentity>());
        });
예제 #2
0
        public IEnumerator OnDestroySpawnHandlerTest() => UniTask.ToCoroutine(async() =>
        {
            spawnDelegateTestCalled = 0;
            int hash                 = Guid.NewGuid().GetHashCode();
            var gameObject           = new GameObject();
            NetworkIdentity identity = gameObject.AddComponent <NetworkIdentity>();
            identity.PrefabHash      = hash;
            identity.NetId           = (uint)Random.Range(0, int.MaxValue);

            UnSpawnDelegate unspawnDelegate = Substitute.For <UnSpawnDelegate>();

            clientObjectManager.RegisterSpawnHandler(hash, SpawnDelegateTest, unspawnDelegate);
            clientObjectManager.RegisterPrefab(identity, hash);
            serverObjectManager.SendSpawnMessage(identity, serverPlayer);

            await AsyncUtil.WaitUntilWithTimeout(() => spawnDelegateTestCalled != 0);

            clientObjectManager.OnObjectDestroy(new ObjectDestroyMessage
            {
                netId = identity.NetId
            });
            unspawnDelegate.Received().Invoke(Arg.Any <NetworkIdentity>());
        });