/// <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); }
public void Invoke(SignalManager signalManager) { foreach (var listener in listeners) { if (ValidateSignalListener(signalManager, listener)) { ((SignalDelegate)listener.SignalDelegate).Invoke(); } } RemoveDiscardedSignalListenerItems(); }
///<summary> /// Helper function that binds the methods decorated with ListenTo attributes in the listener object /// to the corresponding Signal instances in the SignalContext assigned to the signalManager. ///</summary> static public SignalManager BindSignals(SignalManager signalManager, System.Object listenerObject) { if (signalManager != null) { signalManager.BindSignals(listenerObject); return(signalManager); } else { throw new ArgumentException("Attempting to bind signals to a null signalManager"); } }
///<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); } } }
virtual public void Invoke(SignalManager signalManager, params object[] list) { this.Invoke(signalManager); }