public void InvokeCallbacks(EventBase evt)
        {
            bool flag = this.m_Callbacks == null;

            if (!flag)
            {
                this.m_IsInvoking++;
                for (int i = 0; i < this.m_Callbacks.Count; i++)
                {
                    bool isImmediatePropagationStopped = evt.isImmediatePropagationStopped;
                    if (isImmediatePropagationStopped)
                    {
                        break;
                    }
                    this.m_Callbacks[i].Invoke(evt);
                }
                this.m_IsInvoking--;
                bool flag2 = this.m_IsInvoking == 0;
                if (flag2)
                {
                    bool flag3 = this.m_TemporaryCallbacks != null;
                    if (flag3)
                    {
                        EventCallbackRegistry.ReleaseCallbackList(this.m_Callbacks);
                        this.m_Callbacks = EventCallbackRegistry.GetCallbackList(this.m_TemporaryCallbacks);
                        EventCallbackRegistry.ReleaseCallbackList(this.m_TemporaryCallbacks);
                        this.m_TemporaryCallbacks = null;
                    }
                }
            }
        }
        private EventCallbackList GetCallbackListForWriting()
        {
            bool flag = this.m_IsInvoking > 0;
            EventCallbackList result;

            if (flag)
            {
                bool flag2 = this.m_TemporaryCallbacks == null;
                if (flag2)
                {
                    bool flag3 = this.m_Callbacks != null;
                    if (flag3)
                    {
                        this.m_TemporaryCallbacks = EventCallbackRegistry.GetCallbackList(this.m_Callbacks);
                    }
                    else
                    {
                        this.m_TemporaryCallbacks = EventCallbackRegistry.GetCallbackList(null);
                    }
                }
                result = this.m_TemporaryCallbacks;
            }
            else
            {
                bool flag4 = this.m_Callbacks == null;
                if (flag4)
                {
                    this.m_Callbacks = EventCallbackRegistry.GetCallbackList(null);
                }
                result = this.m_Callbacks;
            }
            return(result);
        }
        public void RegisterCallback <TEventType, TUserArgsType>(EventCallback <TEventType, TUserArgsType> callback, TUserArgsType userArgs, TrickleDown useTrickleDown = TrickleDown.NoTrickleDown) where TEventType : EventBase <TEventType>, new()
        {
            if (m_CallbackRegistry == null)
            {
                m_CallbackRegistry = new EventCallbackRegistry();
            }

            m_CallbackRegistry.RegisterCallback <TEventType, TUserArgsType>(callback, userArgs, useTrickleDown);
        }
        public void RegisterCallback <TEventType>(EventCallback <TEventType> callback, TrickleDown useTrickleDown = TrickleDown.NoTrickleDown) where TEventType : EventBase <TEventType>, new()
        {
            bool flag = this.m_CallbackRegistry == null;

            if (flag)
            {
                this.m_CallbackRegistry = new EventCallbackRegistry();
            }
            this.m_CallbackRegistry.RegisterCallback <TEventType>(callback, useTrickleDown);
            GlobalCallbackRegistry.RegisterListeners <TEventType>(this, callback, useTrickleDown);
        }
        public virtual void HandleEvent(EventBase evt)
        {
            bool flag = evt == null;

            if (!flag)
            {
                switch (evt.propagationPhase)
                {
                case PropagationPhase.TrickleDown:
                case PropagationPhase.AtTarget:
                case PropagationPhase.BubbleUp:
                {
                    bool flag2 = !evt.isPropagationStopped;
                    if (flag2)
                    {
                        EventCallbackRegistry expr_4D = this.m_CallbackRegistry;
                        if (expr_4D != null)
                        {
                            expr_4D.InvokeCallbacks(evt);
                        }
                    }
                    break;
                }

                case PropagationPhase.DefaultAction:
                {
                    bool flag3 = !evt.isDefaultPrevented;
                    if (flag3)
                    {
                        using (new EventDebuggerLogExecuteDefaultAction(evt))
                        {
                            this.ExecuteDefaultAction(evt);
                        }
                    }
                    break;
                }

                case PropagationPhase.DefaultActionAtTarget:
                {
                    bool flag4 = !evt.isDefaultPrevented;
                    if (flag4)
                    {
                        using (new EventDebuggerLogExecuteDefaultAction(evt))
                        {
                            this.ExecuteDefaultActionAtTarget(evt);
                        }
                    }
                    break;
                }
                }
            }
        }
        internal void RegisterCallback <TEventType>(EventCallback <TEventType> callback, InvokePolicy invokePolicy, TrickleDown useTrickleDown = TrickleDown.NoTrickleDown) where TEventType : EventBase <TEventType>, new()
        {
            if (m_CallbackRegistry == null)
            {
                m_CallbackRegistry = new EventCallbackRegistry();
            }

            m_CallbackRegistry.RegisterCallback(callback, useTrickleDown, invokePolicy);

            GlobalCallbackRegistry.RegisterListeners <TEventType>(this, callback, useTrickleDown);

            AddEventCategories <TEventType>();
        }
        /// <summary>
        /// Adds an event handler to the instance. If the event handler has already been registered for the same phase (either TrickleDown or BubbleUp) then this method has no effect.
        /// </summary>
        /// <param name="callback">The event handler to add.</param>
        /// <param name="userArgs">Data to pass to the callback.</param>
        /// <param name="useTrickleDown">By default, this callback is called during the BubbleUp phase. Pass TrickleDown.TrickleDown to call this callback during the TrickleDown phase.</param>
        public void RegisterCallback <TEventType, TUserArgsType>(EventCallback <TEventType, TUserArgsType> callback, TUserArgsType userArgs, TrickleDown useTrickleDown = TrickleDown.NoTrickleDown) where TEventType : EventBase <TEventType>, new()
        {
            if (m_CallbackRegistry == null)
            {
                m_CallbackRegistry = new EventCallbackRegistry();
            }

            m_CallbackRegistry.RegisterCallback(callback, userArgs, useTrickleDown, default);

            GlobalCallbackRegistry.RegisterListeners <TEventType>(this, callback, useTrickleDown);

            AddEventCategories <TEventType>();
        }