/// <summary>
        /// Invokes all listeners
        /// </summary>
        private void InvokeAllListeners()
        {
            for (int index = Listeners.Count - 1; index >= 0; index--)
            {
                if (Listeners[index] == null)
                {
                    Listeners.RemoveAt(index);
                    continue;
                }

                if (_debug)
                {
                    Debug.Log($"Listener <b>{Listeners[index]}</b> was called.");
                }

                Listeners[index].OnEventInvoked();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Removes the listener from the specified priority level.
        /// </summary>
        /// <param name="priority">Priority that the listener was registered under.</param>
        /// <param name="callback">Function that was registered as a listener.</param>
        public static void RemoveListener(int priority, EventCallback callback)
        {
            if (callback == null)
            {
                throw new ArgumentException(nameof(callback), $"Trying to remove a callback with null value from event type '{GenericTypeName}'.");
            }

            // Check there is a list of listeners for this priority
            if (Listeners.TryGetValue(priority, out List <EventCallback> listeners))
            {
                listeners.Remove(callback);

                // Remove this priority if there are no more listeners
                if (listeners == null || listeners.Count == 0)
                {
                    Listeners.RemoveAt(priority);
                }
            }
        }