/// <summary> /// Trigger an event with no arguments /// </summary> public static void Trigger(string eventName) { IConcreteUnityEvent thisEvent = null; if (Instance.events0Arg.TryGetValue(eventName, out thisEvent)) { Cast(thisEvent).Invoke(); } }
/// <summary> /// Trigger an event with 3 arguments /// </summary> public static void Trigger <T0, T1, T2>(string eventName, T0 arg0, T1 arg1, T2 arg2) { IConcreteUnityEvent thisEvent = null; if (Instance.events3Arg.TryGetValue(eventName, out thisEvent)) { Cast <T0, T1, T2>(thisEvent).Invoke(arg0, arg1, arg2); } }
/// <summary> /// Trigger an event with 1 argument /// </summary> public static void Trigger <T>(string eventName, T argument) { IConcreteUnityEvent thisEvent = null; if (Instance.events1Arg.TryGetValue(eventName, out thisEvent)) { Cast <T>(thisEvent).Invoke(argument); } }
/// <summary> /// Trigger an event with 2 arguments /// </summary> public static void Trigger <T0, T1>(EventTypes eventName, T0 arg0, T1 arg1) { IConcreteUnityEvent thisEvent = null; if (Instance.events2Arg.TryGetValue(eventName, out thisEvent)) { Cast <T0, T1>(thisEvent).Invoke(arg0, arg1); } }
/// <summary> /// Remove a listener with no arguments /// </summary> public static void OptOut(string eventName, UnityAction listener) { if (manager == null) { return; } IConcreteUnityEvent thisEvent = null; if (Instance.events0Arg.TryGetValue(eventName, out thisEvent)) { Cast(thisEvent).RemoveListener(listener); } }
/// <summary> /// Remove a listener with 3 arguments /// </summary> public static void StopListening <T0, T1, T2>(EventTypes eventName, UnityAction <T0, T1, T2> listener) { if (manager == null) { return; } IConcreteUnityEvent thisEvent = null; if (Instance.events3Arg.TryGetValue(eventName, out thisEvent)) { Cast <T0, T1, T2>(thisEvent).RemoveListener(listener); } }
/// <summary> /// Register a listener for an event using no arguments. /// </summary> public static void OptIn(string eventName, UnityAction listener) { IConcreteUnityEvent thisEvent = null; if (Instance.events0Arg.TryGetValue(eventName, out thisEvent)) { if (!(thisEvent is ConcreteUnityEvent)) { Debug.LogError("This Key is already used for an event with a different signiture: " + eventName); return; } Cast(thisEvent).RemoveListener(listener); // Make sure the same listener is never added more than once Cast(thisEvent).AddListener(listener); } else { thisEvent = new ConcreteUnityEvent(); Cast(thisEvent).AddListener(listener); Instance.events0Arg.Add(eventName, thisEvent); } }
private static ConcreteUnityEvent <T0, T1, T2> Cast <T0, T1, T2>(IConcreteUnityEvent value) { return((ConcreteUnityEvent <T0, T1, T2>)value); }
private static ConcreteUnityEvent <T> Cast <T>(IConcreteUnityEvent value) { return((ConcreteUnityEvent <T>)value); }
// // Utility // private static ConcreteUnityEvent Cast(IConcreteUnityEvent value) { return((ConcreteUnityEvent)value); }