void CheckForLocalPlayer(NetworkIdentity identity) { if (identity && identity == LocalPlayer) { // Set isLocalPlayer to true on this NetworkIdentity and trigger OnStartLocalPlayer in all scripts on the same GO identity.StartLocalPlayer(); if (logger.LogEnabled()) { logger.Log("ClientScene.OnOwnerMessage - player=" + identity.name); } } }
public void OnStartLocalPlayer() { // add components UnityAction funcEx = Substitute.For <UnityAction>(); UnityAction func = Substitute.For <UnityAction>(); identity.OnStartLocalPlayer.AddListener(funcEx); identity.OnStartLocalPlayer.AddListener(func); funcEx .When(f => f.Invoke()) .Do(f => { throw new Exception("Some exception"); }); // make sure that comp.OnStartServer was called // the exception was caught and not thrown in here. Assert.Throws <Exception>(() => { identity.StartLocalPlayer(); }); funcEx.Received(1).Invoke(); //Due to the order the listeners are added the one without exception is never called func.Received(0).Invoke(); // we have checks to make sure that it's only called once. // let's see if they work. Assert.DoesNotThrow(() => { identity.StartLocalPlayer(); }); // same as before? funcEx.Received(1).Invoke(); //Due to the order the listeners are added the one without exception is never called func.Received(0).Invoke(); }