public void Unsubscribe <T>(Events.EventDelegate <T> del) where T : GameEvent { if (Delegates.ContainsKey(del)) { var info = Delegates[del]; Events.Instance.RemoveListener(info.Type, info.Delegate); Delegates.Remove(del); } }
// --------------------------------------------------------------------------------------------------------- /// <summary> /// removes a function that listens for the given event when the event is sent to this object /// </summary> /// <typeparam name="T"></typeparam> /// <param name="del"></param> /// <param name="o"></param> public static void RemoveObjectListener <T>(Events.EventDelegate <T> del, object o) where T : GameEvent // --------------------------------------------------------------------------------------------------------- { DelegateSet delegateSet = Internal.GetDelegates(o); Dbg.Assert(delegateSet != null); // odd otherwise RemoveListener(del, delegateSet); if (delegateSet.Lookup.Count == 0) { Internal.RemoveDelegates(o); } }
public void Subscribe <T>(Events.EventDelegate <T> del) where T : GameEvent { if (!Delegates.ContainsKey(del)) { var info = new EventInfo { Type = typeof(T), Delegate = (e) => del((T)e) }; Delegates.Add(del, info); Events.Instance.AddListener(info.Type, info.Delegate); } }
// ***************** OBJECT FUNCTIONS *************************************************************************** // --------------------------------------------------------------------------------------------------------- /// <summary> /// adds a function that listens for the given event when the event is sent to this object /// </summary> /// <typeparam name="T"></typeparam> /// <param name="del"></param> /// <param name="o"></param> public static void AddObjectListener <T>(Events.EventDelegate <T> del, object o) where T : GameEvent // --------------------------------------------------------------------------------------------------------- { AddListener <T>(del, Internal.GetOrCreateDelegates(o)); }
// --------------------------------------------------------------------------------------------------------- /// <summary> /// removes a function that listens for the given event when the event is sent globally /// </summary> /// <typeparam name="T"></typeparam> /// <param name="del"></param> // --------------------------------------------------------------------------------------------------------- public static void RemoveGlobalListener <T>(Events.EventDelegate <T> del) where T : GameEvent { RemoveListener(del, Internal._globalDelegates); }
protected void Unsubscribe <T>(Events.EventDelegate <T> del) where T : GameEvent { UnityEventOwner.Unsubscribe(del); }