public void TriggerIntEvent(string eventName, int val) { if (string.IsNullOrEmpty(eventName)) { return; } IntResponseEvent gameEvent = null; if (intEventDictionary.TryGetValue(eventName, out gameEvent)) { if (gameEvent != null) { gameEvent.Invoke(val); } } }
public void AddListener(string eventName, UnityAction <int> listener) { IntResponseEvent gameEvent = null; // Try to get the value from the dictionary if (!intEventDictionary.TryGetValue(eventName, out gameEvent)) { // If not, that means the event has not been registered. // So, create it. gameEvent = new IntResponseEvent(); intEventDictionary.Add(eventName, gameEvent); } // Check for existence of gameEvent if (gameEvent != null) { gameEvent.AddListener(listener); } }