/// <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); }
/// <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); } }
private static void CallComponentCallbacks(EventType type, CallbackData data) { try { ComponentEventsContainer cont = null; if (componentEventsNoData.TryGetValue(type, out cont)) { cont.FireIfNotNull(data); } if (componentEventsData.TryGetValue(type, out cont)) { cont.FireIfNotNull(data); } } catch (Exception e) { Logger.Error("Failed to execute event callbacks: " + e.Message + "\n\nError stack trace:\n" + e.StackTrace + "\n\n"); } }