| //-------------------------------------------------------- | 
| //    [Author]:           玩个游戏 | 
| //    [  Date ]:           Saturday, November 25, 2017 | 
| //-------------------------------------------------------- | 
| using UnityEngine; | 
| using UnityEngine.Events; | 
| using UnityEngine.EventSystems; | 
| using System.Collections.Generic; | 
| using System; | 
|   | 
|   | 
|     [RequireComponent(typeof(RectTransform))] | 
|     public class FakeButton : MonoBehaviour, IPointerClickHandler, IPointerDownHandler, IPointerUpHandler, IDragHandler | 
|     { | 
|         RectTransform m_RectTransform; | 
|         public RectTransform rectTransform { get { return m_RectTransform ?? (m_RectTransform = this.transform as RectTransform); } } | 
|   | 
|         Action m_OnClick; | 
|   | 
|         public void AddListener(Action action) | 
|         { | 
|             m_OnClick += action; | 
|         } | 
|   | 
|         public void RemoveAllListeners() | 
|         { | 
|             m_OnClick = null; | 
|         } | 
|   | 
|         public void OnPointerUp(PointerEventData eventData) | 
|         { | 
|             PassEvent(eventData, ExecuteEvents.pointerUpHandler); | 
|         } | 
|   | 
|         public void OnPointerDown(PointerEventData eventData) | 
|         { | 
|             PassEvent(eventData, ExecuteEvents.pointerDownHandler); | 
|         } | 
|   | 
|         public void OnDrag(PointerEventData eventData) | 
|         { | 
|             PassEvent(eventData, ExecuteEvents.dragHandler); | 
|         } | 
|   | 
|         public void OnPointerClick(PointerEventData eventData) | 
|         { | 
|             m_OnClick?.Invoke(); | 
|             PassEvent(eventData, ExecuteEvents.submitHandler); | 
|             PassEvent(eventData, ExecuteEvents.pointerClickHandler); | 
|         } | 
|   | 
|         public void PassEvent<T>(PointerEventData data, ExecuteEvents.EventFunction<T> function) where T : IEventSystemHandler | 
|         { | 
|             List<RaycastResult> results = new List<RaycastResult>(); | 
|             EventSystem.current.RaycastAll(data, results); | 
|             GameObject current = data.pointerCurrentRaycast.gameObject; | 
|             for (int i = 0; i < results.Count; i++) | 
|             { | 
|                 if (current != results[i].gameObject) | 
|                 { | 
|                     if (ExecuteEvents.Execute(results[i].gameObject, data, function)) | 
|                     { | 
|                         break; | 
|                     } | 
|                 } | 
|             } | 
|         } | 
|   | 
|   | 
|     } |