/// <summary> /// Unsubscribes a callback from an event /// </summary> /// <param name="callback"></param> /// <param name="type"></param> public static void UnsubscribeFromEvent(EventDataCallback callback, EventType type) { if (eventsData.ContainsKey(type)) { eventsData[type] = Delegate.RemoveAll(eventsData[type], callback); } }
public static void UnsubscribeFromEvent(EventDataCallback callback, Component component, EventType type) { CallbackComponentPair pair = new CallbackComponentPair(callback, component); if (componentEventsData.ContainsKey(type)) { componentEventsData[type].Unsubscribe(pair); } }
/// <summary> /// Subscribe to an event with a callback. This removes all previous subscriptions for this event. /// </summary> /// <param name="callback"></param> /// <param name="type"></param> public static void OverrideSubscription(EventDataCallback callback, Component component, EventType type) { CallbackComponentPair pair = new CallbackComponentPair(callback, component); ComponentEventsContainer cont = new ComponentEventsContainer(); cont.AddPair(pair); componentEventsData.Add(type, cont); }
public void RegisterEventCode(EventCode code, EventDataCallback callback) { if (EventDataContain.ContainsKey(code)) { EventDataContain[code] += callback; } else { EventDataContain[code] = callback; } }
/// <summary> /// Subscribe to an event with a callback from a component. The subscription is removed automatically when the component is destroyed. /// </summary> /// <param name="callback"></param> /// <param name="component"></param> /// <param name="type"></param> public static void SubscribeToEvent(EventDataCallback callback, Component component, EventType type) { CallbackComponentPair pair = new CallbackComponentPair(callback, component); if (!componentEventsData.ContainsKey(type)) { ComponentEventsContainer cont = new ComponentEventsContainer(); cont.AddPair(pair); componentEventsData.Add(type, cont); } else { componentEventsData[type].AddPair(pair); } }
public void UnRegisterEventCode(EventCode code, EventDataCallback callback) { if (EventDataContain.ContainsKey(code)) { EventDataContain[code] -= callback; if (EventDataContain[code] == null) { EventDataContain.Remove(code); } } else { Debug.LogWarning("未注册事件:" + code.ToString()); } }
/// <summary> /// Subscribe to an event with a callback. This removes all previous subscriptions for this event. /// </summary> /// <param name="callback"></param> /// <param name="type"></param> public static void OverrideSubscription(EventDataCallback callback, EventType type) { SetValueDelegateDictionary(eventsData, type, callback); }
/// <summary> /// Subscribe to an event with a callback /// </summary> /// <param name="callback"></param> /// <param name="type"></param> public static void SubscribeToEvent(EventDataCallback callback, EventType type) { AddToDelegateDictionary <EventType>(eventsData, type, callback); }