Example #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 UIPointerDownEventListener CheckAndAddListener(GameObject obj)
        {
            UIPointerDownEventListener listener = obj.GetComponent <UIPointerDownEventListener>();

            if (listener == null)
            {
                listener = obj.AddComponent <UIPointerDownEventListener>();
            }

            return(listener);
        }