public static async UniTask <NetworkIdentity> WaitUntilSpawn(NetworkWorld world, uint netId) { NetworkIdentity identity = null; await UniTask.WaitUntil(() => world.TryGetIdentity(netId, out identity)); return(identity); }
public void SetUp() { world = new NetworkWorld(); spawnListener = Substitute.For <Action <NetworkIdentity> >(); unspawnListener = Substitute.For <Action <NetworkIdentity> >(); world.onSpawn += spawnListener; world.onUnspawn += unspawnListener; existingIds = new HashSet <uint>(); }
void CheckPlayersNotInList() { NetworkWorld world = NetworkManager.Server.Active ? NetworkManager.Server.World : NetworkManager.Client.World; foreach (NetworkIdentity identity in world.SpawnedIdentities) { Tank comp = identity.GetComponent <Tank>(); if (comp != null && !players.Contains(comp)) { //Add if new players.Add(comp); } } }
public IEnumerator DestroyAllSpawnedOnStopTest() => UniTask.ToCoroutine(async() => { var spawnTestObj = new GameObject("testObj", typeof(NetworkIdentity)); serverObjectManager.Spawn(spawnTestObj); // need to grab reference to world before Stop, becuase stop will clear reference NetworkWorld world = server.World; //1 is the player. should be 2 at this point Assert.That(world.SpawnedIdentities.Count, Is.GreaterThan(1)); server.Stop(); await AsyncUtil.WaitUntilWithTimeout(() => !server.Active); Assert.That(world.SpawnedIdentities.Count, Is.Zero); // checks that the object was destroyed // use unity null check here Assert.IsTrue(spawnTestObj == null); });