public void CallsUnspawnHandlerInsteadOfDestroy() { // sceneId 0 is prefab TestListenerBehaviour listener1 = CreateAndAddObject(0); TestListenerBehaviour listener2 = CreateAndAddObject(0); Guid guid1 = Guid.NewGuid(); Guid guid2 = Guid.NewGuid(); int unspawnCalled1 = 0; int unspawnCalled2 = 0; unspawnHandlers.Add(guid1, x => unspawnCalled1++); unspawnHandlers.Add(guid2, x => unspawnCalled2++); listener1.GetComponent <NetworkIdentity>().assetId = guid1; listener2.GetComponent <NetworkIdentity>().assetId = guid2; int disableCalled1 = 0; int disableCalled2 = 0; listener1.onDisableCalled += () => disableCalled1++; listener2.onDisableCalled += () => disableCalled2++; NetworkClient.DestroyAllClientObjects(); Assert.That(unspawnCalled1, Is.EqualTo(1)); Assert.That(unspawnCalled2, Is.EqualTo(1)); Assert.That(disableCalled1, Is.EqualTo(0), "Object with UnspawnHandler should not be destroyed"); Assert.That(disableCalled2, Is.EqualTo(0), "Object with UnspawnHandler should not be destroyed"); }
public IEnumerator DisablesAllNetworkSceneObjectsInScene() { // sceneId 0 is prefab TestListenerBehaviour listener1 = CreateAndAddObject(101); TestListenerBehaviour listener2 = CreateAndAddObject(102); int disableCalled1 = 0; int disableCalled2 = 0; listener1.onDisableCalled += () => disableCalled1++; listener2.onDisableCalled += () => disableCalled2++; int destroyCalled1 = 0; int destroyCalled2 = 0; listener1.onDestroyCalled += () => destroyCalled1++; listener2.onDestroyCalled += () => destroyCalled2++; NetworkClient.DestroyAllClientObjects(); // wait for frame to make sure unity events are called yield return(null); Assert.That(disableCalled1, Is.EqualTo(1)); Assert.That(disableCalled2, Is.EqualTo(1)); Assert.That(destroyCalled1, Is.EqualTo(0), "Scene objects should not be destroyed"); Assert.That(destroyCalled2, Is.EqualTo(0), "Scene objects should not be destroyed"); }
public void CatchesAndLogsExeptionWhenSpawnedListIsChanged() { // create spawned (needs to be added to .spawned!) CreateNetworkedAndSpawn(out GameObject badGameObject, out NetworkIdentity identity, out BadBehaviour bad); LogAssert.Expect(LogType.Exception, new Regex("InvalidOperationException")); LogAssert.Expect(LogType.Error, "Could not DestroyAllClientObjects because spawned list was modified during loop, make sure you are not modifying NetworkIdentity.spawned by calling NetworkServer.Destroy or NetworkServer.Spawn in OnDestroy or OnDisable."); NetworkClient.DestroyAllClientObjects(); }
public void ClearsSpawnedList() { // sceneId 0 is prefab CreateAndAddObject(0, out TestListenerBehaviour serverComp, out TestListenerBehaviour clientComp); NetworkClient.DestroyAllClientObjects(); Assert.That(NetworkClient.spawned, Is.Empty); }
public void ClearsSpawnedList() { // sceneId 0 is prefab TestListenerBehaviour listener1 = CreateAndAddObject(0); TestListenerBehaviour listener2 = CreateAndAddObject(0); NetworkClient.DestroyAllClientObjects(); Assert.That(NetworkClient.spawned, Is.Empty); }
public void CatchesAndLogsExeptionWhenSpawnedListIsChanged() { GameObject badGameObject = new GameObject("bad", typeof(NetworkIdentity), typeof(BadBehaviour)); NetworkIdentity netId = badGameObject.GetComponent <NetworkIdentity>(); const int id = 3535; netId.netId = id; spawned.Add(id, netId); LogAssert.Expect(LogType.Exception, new Regex("InvalidOperationException")); LogAssert.Expect(LogType.Error, "Could not DestroyAllClientObjects because spawned list was modified during loop, make sure you are not modifying NetworkIdentity.spawned by calling NetworkServer.Destroy or NetworkServer.Spawn in OnDestroy or OnDisable."); NetworkClient.DestroyAllClientObjects(); }
public IEnumerator DestroysAllNetworkPrefabsInScene() { // sceneId 0 is prefab CreateAndAddObject(0, out TestListenerBehaviour serverComp, out TestListenerBehaviour clientComp); int destroyCalled = 0; clientComp.onDestroyCalled += () => destroyCalled++; NetworkClient.DestroyAllClientObjects(); // wait for frame to make sure unity events are called yield return(null); Assert.That(destroyCalled, Is.EqualTo(1)); }
public IEnumerator DestroysAllNetworkPrefabsInScene() { // sceneId 0 is prefab TestListenerBehaviour listener1 = CreateAndAddObject(0); TestListenerBehaviour listener2 = CreateAndAddObject(0); int destroyCalled1 = 0; int destroyCalled2 = 0; listener1.onDestroyCalled += () => destroyCalled1++; listener2.onDestroyCalled += () => destroyCalled2++; NetworkClient.DestroyAllClientObjects(); // wait for frame to make sure unity events are called yield return(null); Assert.That(destroyCalled1, Is.EqualTo(1)); Assert.That(destroyCalled2, Is.EqualTo(1)); }
public IEnumerator DisablesAllNetworkSceneObjectsInScene() { // sceneId 0 is prefab CreateAndAddObject(101, out TestListenerBehaviour serverComp, out TestListenerBehaviour clientComp); int disableCalled = 0; clientComp.onDisableCalled += () => disableCalled++; int destroyCalled = 0; clientComp.onDestroyCalled += () => destroyCalled++; NetworkClient.DestroyAllClientObjects(); // wait for frame to make sure unity events are called yield return(null); Assert.That(disableCalled, Is.EqualTo(1)); Assert.That(destroyCalled, Is.EqualTo(0), "Scene objects should not be destroyed"); }
public void CallsUnspawnHandlerInsteadOfDestroy() { // sceneId 0 is prefab CreateAndAddObject(0, out TestListenerBehaviour serverComp, out TestListenerBehaviour clientComp); Guid guid1 = Guid.NewGuid(); int unspawnCalled = 0; unspawnHandlers.Add(guid1, x => unspawnCalled++); clientComp.GetComponent <NetworkIdentity>().assetId = guid1; int disableCalled = 0; clientComp.onDisableCalled += () => disableCalled++; NetworkClient.DestroyAllClientObjects(); Assert.That(unspawnCalled, Is.EqualTo(1)); Assert.That(disableCalled, Is.EqualTo(0), "Object with UnspawnHandler should not be destroyed"); }