예제 #1
0
 /// <summary>
 /// 取消事件监听
 /// </summary>
 /// <param name="type"></param>
 /// <param name="handler"></param>
 public void UnSubscribe(UIEventEnum type, EventHandler <GameEventArgs> handler)
 {
     if (Check(type, handler))
     {
         UIEventHandlerList[type].Remove(handler);
     }
 }
예제 #2
0
 /// <summary>
 /// 注册事件
 /// </summary>
 /// <param name="id"></param>
 /// <param name="handler"></param>
 public void Subscribe(UIEventEnum type, EventHandler <GameEventArgs> handler)
 {
     if (!UIEventHandlerList.ContainsKey(type))
     {
         UIEventHandlerList.Add(type, new List <EventHandler <GameEventArgs> >());
     }
     UIEventHandlerList[type].Add(handler);
 }
예제 #3
0
 /// <summary>
 /// 检查事件是否注册
 /// </summary>
 /// <param name="id"></param>
 /// <param name="handler"></param>
 /// <returns></returns>
 public bool Check(UIEventEnum type, EventHandler <GameEventArgs> handler)
 {
     if (!UIEventHandlerList.ContainsKey(type))
     {
         return(false);
     }
     else if (!UIEventHandlerList[type].Contains(handler))
     {
         return(false);
     }
     return(true);
 }
예제 #4
0
 /// <summary>
 /// 发送事件
 /// </summary>
 /// <param name="type">事件类型</param>
 /// <param name="sender">发送者</param>
 /// <param name="e">需要传递的信息</param>
 public void Fire(UIEventEnum type, GameObject sender = null, GameEventArgs e = null)
 {
     if (UIEventHandlerList.ContainsKey(type))
     {
         if (UIEventHandlerList[type].Count > 0)
         {
             for (int i = 0; i < UIEventHandlerList[type].Count; i++)
             {
                 UIEventHandlerList[type][i](sender, e);
             }
         }
     }
 }
예제 #5
0
        //=================== 事件 ==========================
        /// <summary>
        /// 添加组件监听事件
        /// </summary>
        /// <param name="objCan"></param>
        /// <param name="eventTypeCan"></param>
        /// <param name="callbackCan"></param>
        public void AddComponentCallbackListnener(GameObject objCan, UIEventEnum eventEnumCan, VoidDelegate callbackCan)
        {
            UIEventListener.AddEventListener(objCan, eventEnumCan, callbackCan);
            List <GameObject> tempObjList = null;

            if (compDelegateDic.TryGetValue(eventEnumCan, out tempObjList))
            {
                compDelegateDic[eventEnumCan].Add(objCan);
            }
            else
            {
                tempObjList = new List <GameObject>();
                tempObjList.Add(objCan);
                compDelegateDic.Add(eventEnumCan, tempObjList);
            }
        }
예제 #6
0
        /// <summary>
        /// 移除组件监听事件
        /// </summary>
        /// <param name="objCan"></param>
        /// <param name="eventEnumCan"></param>
        public void RemoveComponentCallbackListnener(GameObject objCan, UIEventEnum eventEnumCan)
        {
            List <GameObject> tempObjList = null;

            if (compDelegateDic.TryGetValue(eventEnumCan, out tempObjList))
            {
                int tempCount = tempObjList.Count - 1;
                for (int i = 0; i < tempCount; i++)
                {
                    if (tempObjList[i] == objCan)
                    {
                        UIEventListener.RemoveEventListener(compDelegateDic[eventEnumCan][i], eventEnumCan);
                        compDelegateDic[eventEnumCan].RemoveAt(i);
                    }
                }
            }
        }
        static public bool AddEventListener(GameObject go, UIEventEnum tempEnum, VoidDelegate tempDelegate)
        {
            UIEventListener listener = go.GetComponent <UIEventListener>();

            if (listener == null)
            {
                listener = go.AddComponent <UIEventListener>();
            }
            switch (tempEnum)
            {
            case UIEventEnum.ON_CLICK:
                listener.onClick = tempDelegate;
                return(true);

            case UIEventEnum.ON_DOWN:
                listener.onDown = tempDelegate;
                return(true);

            case UIEventEnum.ON_ENTER:
                listener.onEnter = tempDelegate;
                return(true);

            case UIEventEnum.ON_EXIT:
                listener.onExit = tempDelegate;
                return(true);

            case UIEventEnum.ON_UP:
                listener.onUp = tempDelegate;
                return(true);

            case UIEventEnum.ON_SELECT:
                listener.onSelect = tempDelegate;
                return(true);

            case UIEventEnum.ON_UPDATESELECT:
                listener.onUpdateSelect = tempDelegate;
                return(true);
            }
            return(false);
        }
        static public bool RemoveEventListener(GameObject go, UIEventEnum tempEnum)
        {
            UIEventListener listener = go.GetComponent <UIEventListener>();

            if (listener == null)
            {
                ZLogger.Error("GameObject {0} don't have UIEventListener", go.name);
                return(false);
            }
            switch (tempEnum)
            {
            case UIEventEnum.ON_CLICK:
                if (listener.onClick != null)
                {
                    listener.onClick = null;
                }
                return(true);

            case UIEventEnum.ON_DOWN:
                if (listener.onDown != null)
                {
                    listener.onDown = null;
                }
                return(true);

            case UIEventEnum.ON_ENTER:
                if (listener.onEnter != null)
                {
                    listener.onEnter = null;
                }
                return(true);

            case UIEventEnum.ON_EXIT:
                if (listener.onExit != null)
                {
                    listener.onExit = null;
                }
                return(true);

            case UIEventEnum.ON_UP:
                if (listener.onUp != null)
                {
                    listener.onUp = null;
                }
                return(true);

            case UIEventEnum.ON_SELECT:
                if (listener.onSelect != null)
                {
                    listener.onSelect = null;
                }
                return(true);

            case UIEventEnum.ON_UPDATESELECT:
                if (listener.onUpdateSelect != null)
                {
                    listener.onUpdateSelect = null;
                }
                return(true);
            }
            return(false);
        }
예제 #9
0
 public static string Event(UITypeEnum UIType, UIEventEnum state)
 {
     return(string.Format("UIEvents.{0}.{1}", UIType, state));
 }