/// <summary> /// Removes the action at observer specified by notification name /// </summary> /// <param name="notificationName">Notification name.</param> /// <param name="action">Action.</param> public static void RemoveActionAtObserver(string notificationName, System.Action <Parameters> action) { if (eventObservers.ContainsKey(notificationName)) { ObserverList eventObserver = eventObservers[notificationName]; eventObserver.RemoveObserver(action); } }
/// <summary> /// Posts an event specified by name that does not require any parameters. /// Observers associated with this event will be called. /// </summary> public static void PostEvent(string notificationName) { if (eventObservers.ContainsKey(notificationName)) { ObserverList eventObserver = eventObservers[notificationName]; eventObserver.NotifyObservers(); } }
public static void AddObserver(string notificationName, System.Action action) { //if there is already an existing key, add the listener to the observer list if (eventObservers.ContainsKey(notificationName)) { ObserverList eventObserver = eventObservers[notificationName]; eventObserver.AddObserver(action); } //create a new instance of an observer list else { ObserverList eventObserver = new ObserverList(); eventObserver.AddObserver(action); eventObservers.Add(notificationName, eventObserver); } }