public void OnNetworkDestroy() { // add components NetworkDestroyExceptionNetworkBehaviour compEx = gameObject.AddComponent <NetworkDestroyExceptionNetworkBehaviour>(); identity.OnNetworkDestroy.AddListener(compEx.OnNetworkDestroy); NetworkDestroyCalledNetworkBehaviour comp = gameObject.AddComponent <NetworkDestroyCalledNetworkBehaviour>(); identity.OnNetworkDestroy.AddListener(comp.OnNetworkDestroy); // make sure our test values are set to 0 Assert.That(compEx.called, Is.EqualTo(0)); Assert.That(comp.called, Is.EqualTo(0)); // we have checks to make sure that it's only called once. // let's see if they work. Assert.Throws <Exception>(() => { identity.NetworkDestroy(); }); Assert.That(compEx.called, Is.EqualTo(1)); //Due to the order the listeners are added the one without exception is never called Assert.That(comp.called, Is.EqualTo(0)); }
public void OnNetworkDestroy() { // create a networkidentity with our test components GameObject gameObject = new GameObject(); NetworkIdentity identity = gameObject.AddComponent <NetworkIdentity>(); NetworkDestroyExceptionNetworkBehaviour compEx = gameObject.AddComponent <NetworkDestroyExceptionNetworkBehaviour>(); NetworkDestroyCalledNetworkBehaviour comp = gameObject.AddComponent <NetworkDestroyCalledNetworkBehaviour>(); // make sure our test values are set to 0 Assert.That(compEx.called, Is.EqualTo(0)); Assert.That(comp.called, Is.EqualTo(0)); // call OnNetworkDestroy in identity // one component will throw an exception, but that shouldn't stop // OnNetworkDestroy from being called in the second one LogAssert.ignoreFailingMessages = true; // exception will log an error identity.OnNetworkDestroy(); LogAssert.ignoreFailingMessages = false; Assert.That(compEx.called, Is.EqualTo(1)); Assert.That(comp.called, Is.EqualTo(1)); // clean up GameObject.DestroyImmediate(gameObject); }