Exemplo n.º 1
0
    private void removeListener(Dictionary <Int32, EventAction> eventHandlers, Int32 evtType, EventAction handler)
    {
        EventAction exists = getHandler(eventHandlers, evtType);

        if (exists != null)
        {
            if (exists.GetInvocationList().Contains(handler))
            {
                exists -= handler;
                eventHandlers[evtType] = exists;
            }
            if (exists == null || exists.GetInvocationList().Length == 0)
            {
                eventHandlers.Remove(evtType);
            }
        }
    }
Exemplo n.º 2
0
        private void removeListener(Dictionary <string, EventAction> eventDic, string evtId, EventAction handler)
        {
            EventAction eventAction = getHandler(eventDic, evtId);

            if (eventAction != null)
            {
                if (eventAction.GetInvocationList().Contains(handler))
                {
                    eventAction    -= handler;
                    eventDic[evtId] = eventAction;
                }

                if (eventAction == null || eventAction.GetInvocationList().Length == 0)
                {
                    eventDic.Remove(evtId);
                }
            }
        }
Exemplo n.º 3
0
        private void addListener(Dictionary <string, EventAction> eventDic, string evtId, EventAction handler)
        {
            EventAction eventAction = getHandler(eventDic, evtId);

            if (eventAction != null)
            {
                if (!eventAction.GetInvocationList().Contains(handler))
                {
                    eventAction += handler;
                }
                else
                {
                    Debug.LogWarning($"handler:{nameof(handler)} has already exist with evtId {evtId},you can not add again");
                }
            }
            else
            {
                eventAction = handler;
            }
            eventDic[evtId] = eventAction;
        }
Exemplo n.º 4
0
    private void addListener(Dictionary <Int32, EventAction> eventHandlers, Int32 evtType, EventAction handler)
    {
        EventAction exists = getHandler(eventHandlers, evtType);

        if (exists != null)
        {
            if (!exists.GetInvocationList().Contains(handler))
            {
                exists += handler;
            }
            else
            {
                UnityEngine.Debug.LogError("多次添加事件:" + evtType.ToString());
            }
        }
        else
        {
            exists = handler;
        }
        eventHandlers[evtType] = exists;
    }