/// <summary> /// Note: This method validates that the target listener object is still around, if the /// listener object is null, it removes any delegates bound to that object. This is the /// only part of the code that is Unity specific. If you'd like to us SimpleSignals in /// a vanilla C# enviornment, this is the only method that needs to be tweaked. /// </summary> protected bool ValidateSignalListener(SignalManager signalManager, SignalListenerItem listener) { bool isInvokable = true; object target = listener.SignalDelegate.Target; // <UnitySpecific> // Comment this code out if you're not using MonoBehaviors if (target is MonoBehaviour) { MonoBehaviour targetGO = (MonoBehaviour)target; // Don't invoke listeners on destroyed GameObjects instead Clean up listeners if (targetGO == null && !ReferenceEquals(targetGO, null)) { isInvokable = false; SignalManager.UnbindSignals(signalManager, targetGO); } } // </UnitySpecific> // This listener delegate will be removed after it's invoked if (listener.ListenerType == ListenerType.Once) { this.listenersToRemove.Add(listener); } return(isInvokable); }
///<summary> /// Helper function that unbinds any signal listeners in the listenerObject from any Signal instances /// in the SignalContext assigned to the specified signalManager. ///</summary> static public void UnbindSignals(SignalManager signalManager, System.Object listenerObject) { if (signalManager != null) { if (signalManager.isInvoking) { signalManager.objectsToUnbind.Add(listenerObject); } else { signalManager.UnbindSignals(listenerObject); } } }