public void StartListening(string eventName, UnityAction <ParamsObject> listener) { if (eventDictionary == null) { eventDictionary = new Dictionary <string, ParamsEvent>(); lastEventValues = new Dictionary <string, ParamsObject>(); } ParamsEvent thisEvent = null; if (eventDictionary.TryGetValue(eventName, out thisEvent)) { thisEvent.AddListener(listener); } else { thisEvent = new ParamsEvent(); thisEvent.AddListener(listener); eventDictionary.Add(eventName, thisEvent); } ParamsObject paramsObj = null; if (lastEventValues != null && lastEventValues.TryGetValue(eventName, out paramsObj)) { if (paramsObj != null) { listener.Invoke(paramsObj); } } }
public static void StartListening(string eventName, UnityAction <ParamsObject> listener) { ParamsEvent thisEvent = null; if (instance.eventDictionary.TryGetValue(eventName, out thisEvent)) { thisEvent.AddListener(listener); } else { thisEvent = new ParamsEvent(); thisEvent.AddListener(listener); instance.eventDictionary.Add(eventName, thisEvent); } ParamsObject paramsObj = null; if (instance.lastEventValues != null && instance.lastEventValues.TryGetValue(eventName, out paramsObj)) { if (paramsObj != null) { listener.Invoke(paramsObj); } } }
public void StopListening(string eventName, UnityAction <ParamsObject> listener) { ParamsEvent thisEvent = null; if (eventDictionary.TryGetValue(eventName, out thisEvent)) { thisEvent.RemoveListener(listener); } }
void Start() { myEvent = new UnityEvent(); myEvent.AddListener(FireFunction); myEvent.AddListener(AnotherFireFunction); paramsEvent = new ParamsEvent(); paramsEvent.AddListener(FireFunctionWithParams); myEvent.Invoke(); paramsEvent.Invoke("hello", 22); paramsEvent.Invoke("jdawgs", 8008135); }
public static void StopListening(string eventName, UnityAction <ParamsObject> listener) { if (eventManager == null) { return; } ParamsEvent thisEvent = null; if (instance.eventDictionary.TryGetValue(eventName, out thisEvent)) { thisEvent.RemoveListener(listener); } }
public static void TriggerEvent(string eventName, ParamsObject paramsObj = null) { ParamsEvent thisEvent = null; if (instance.eventDictionary.TryGetValue(eventName, out thisEvent)) { thisEvent.Invoke(paramsObj); } if (instance.lastEventValues != null) { instance.lastEventValues[eventName] = paramsObj; } }
public void TriggerEvent(string eventName, ParamsObject paramsObj = null) { if (eventDictionary == null) { eventDictionary = new Dictionary <string, ParamsEvent>(); lastEventValues = new Dictionary <string, ParamsObject>(); } ParamsEvent thisEvent = null; if (eventDictionary.TryGetValue(eventName, out thisEvent)) { thisEvent.Invoke(paramsObj); lastEventValues[eventName] = paramsObj; } }
public bool RegisterEvent(string key, UnityAction <object[]> listener) { if (eventMap.ContainsKey(key)) { ParamsEvent paramsEvent; if (eventMap.TryGetValue(key, out paramsEvent)) { //functionPrototype += eventFunction; paramsEvent.AddListener(listener); //eventMap[key] = functionPrototype; } } else { //ParamsEvent functionPrototype = eventFunction; ParamsEvent newEvent = new ParamsEvent(); newEvent.AddListener(listener); eventMap.Add(key, newEvent); } return(true); }