示例#1
0
    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);
            }
        }
    }
示例#2
0
    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);
        }
    }