示例#1
0
        public EventListenerCustom AddCustomEventListener(string eventName, EventListenerCustom.OnEventCustomHandler callback, object addition)
        {
            EventListenerCustom listener = null;

            if (_custom.ContainsKey(eventName))
            {
                listener = _custom[eventName];
                if (listener == null)
                {
                    listener           = new EventListenerCustom(eventName, callback, addition);
                    _custom[eventName] = listener;
                }
                else
                {
                    // remove
                    _custom.Remove(eventName);
                    listener           = new EventListenerCustom(eventName, callback, addition);
                    _custom[eventName] = listener;
                }
            }
            else
            {
                listener           = new EventListenerCustom(eventName, callback, addition);
                _custom[eventName] = listener;
            }

            return(listener);
        }
示例#2
0
 public void PubCustomEvent(string eventName, object ud)
 {
     try {
         if (_customSub.ContainsKey(eventName))
         {
             List <EventListenerCustom> li = _customSub[eventName];
             if (li.Count > 0)
             {
                 for (int i = 0; i < li.Count; i++)
                 {
                     EventListenerCustom listener = li[i];
                     if (listener.Enable)
                     {
                         EventCustom e = new EventCustom(_ctx, eventName, listener.Addition, ud);
                         listener.Handler(e);
                     }
                 }
             }
         }
         else
         {
             throw new KeyNotFoundException(string.Format("custom not contains {0}", eventName));
         }
     } catch (Exception ex) {
         UnityEngine.Debug.LogException(ex);
     }
 }
示例#3
0
        public bool UnsubCustomEventListener(EventListenerCustom listener)
        {
            List <EventListenerCustom> li = null;

            if (_customSub.ContainsKey(listener.Name))
            {
                li = _customSub[listener.Name];
                return(li.Remove(listener));
            }
            else
            {
                return(false);
            }
        }
示例#4
0
 private void DispatchCustomEvent(string eventName, object ud)
 {
     try {
         if (_custom.ContainsKey(eventName))
         {
             EventListenerCustom listener = _custom[eventName];
             if (listener.Enable)
             {
                 EventCustom e = new EventCustom(_ctx, eventName, listener.Addition, ud);
                 listener.Handler(e);
             }
         }
         else
         {
             throw new KeyNotFoundException(string.Format("custom not contains {0}", eventName));
         }
     } catch (Exception ex) {
         UnityEngine.Debug.LogException(ex);
     }
 }
示例#5
0
        public EventListenerCustom SubCustomEventListener(string eventName, EventListenerCustom.OnEventCustomHandler callback, object addition)
        {
            List <EventListenerCustom> li = null;

            if (_custom.ContainsKey(eventName))
            {
                li = _customSub[eventName];
                var listener = new EventListenerCustom(eventName, callback, addition);
                li.Add(listener);
                return(listener);
            }
            else
            {
                li = new List <EventListenerCustom>();
                var listener = new EventListenerCustom(eventName, callback, addition);
                li.Add(listener);
                _customSub[eventName] = li;
                return(listener);
            }
        }