예제 #1
0
        /// <summary>
        /// Simple wrapper for onclick event
        /// </summary>
        /// <param name="selfBtn"></param>
        /// <param name="onClickEvent"></param>
        public static void RegOnClickEvent(this Button selfBtn, UnityAction onClickEvent,
                                           UnityAction onBeforeClickEvent = null, UnityAction onPointerUpEvent = null)
        {
            if (null != onBeforeClickEvent)
            {
                UIPointerDownEventListener.Get(selfBtn.gameObject).OnPointerDownEvent += delegate(PointerEventData arg0)
                {
                    onBeforeClickEvent.InvokeGracefully();
                    ExecuteEvents.Execute <Button>(selfBtn.gameObject, arg0,
                                                   delegate(Button handler, BaseEventData data)
                    {
                        handler.OnPointerDown(data as PointerEventData);
                    });
                };
            }


            if (null != onPointerUpEvent)
            {
                UIPointerUpEventListener.Get(selfBtn.gameObject).OnPointerUpEvent += delegate(PointerEventData arg0)
                {
                    onPointerUpEvent.InvokeGracefully();
                    ExecuteEvents.Execute <Button>(selfBtn.gameObject, arg0,
                                                   delegate(Button handler, BaseEventData data)
                    {
                        handler.OnPointerUp(data as PointerEventData);
                    });
                };
            }

            selfBtn.onClick.AddListener(onClickEvent);
        }
 public static void UnRegisterOnPointerUp <T>(this T selfComponent, Action <PointerEventData> onPointerUpAction)
     where T : Component
 {
     UIPointerUpEventListener.Get(selfComponent.gameObject).OnPointerUpEvent -= onPointerUpAction;
 }
 public static void UnRegisterOnPointerUp(this GameObject selfObj, Action <PointerEventData> onPointerUpAction)
 {
     UIPointerUpEventListener.Get(selfObj).OnPointerUpEvent -= onPointerUpAction;
 }