/// <summary> /// Registers an event listener. /// </summary> /// <param name="injection">The event listener info.</param> public static void RegisterEvent(EventInjection injection) { HashSet<EventInjection> listeners; if (!eventMap.TryGetValue(injection.inject.Name, out listeners)) { listeners = new HashSet<EventInjection>(); eventMap.Add(injection.inject.Name, listeners); } listeners.Add(injection); }
private static void FireEvent(EventInjection injection, object[] args) { MonoBehaviour component = injection.component; MethodInfo method = injection.method; try { object result = method.Invoke(component, args); // Allow for Unity style coroutines to be used if (result is IEnumerator) { component.StartCoroutine((IEnumerator)result); } } catch (System.Exception e) { Debug.LogError(injection); Debug.LogError(e); } }
/// <summary> /// Unregisters an event listener. /// </summary> /// <param name="injection">The event listener info.</param> public static void UnregisterEvent(EventInjection injection) { HashSet<EventInjection> listeners; if (eventMap.TryGetValue(injection.inject.Name, out listeners)) { listeners.Remove(injection); } }