/// <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 RemoveListener(Delegate listener) { SignalListenerItem itemToRemove = new SignalListenerItem(); foreach (var listenerItem in listeners) { if (listenerItem.SignalDelegate == listener) { itemToRemove = listenerItem; break; } } if (itemToRemove.SignalDelegate != null) { this.listeners.Remove(itemToRemove); } }