//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Saturday, November 25, 2017 //-------------------------------------------------------- using UnityEngine; using System.Collections; using UnityEngine.UI; using UnityEngine.Events; namespace vnxbqy.UI { [RequireComponent(typeof(RectTransform))] public class FakeButton2 : MonoBehaviour { RectTransform m_RectTransform; public RectTransform rectTransform { get { return m_RectTransform ?? (m_RectTransform = this.transform as RectTransform); } } float overTime = float.MaxValue; UIEvent m_OnClick = new UIEvent(); public void AddListener(UnityAction _callBack) { m_OnClick.AddListener(_callBack); } public void RemoveAllListeners() { m_OnClick.RemoveAllListeners(); } private void LateUpdate() { if (Input.GetMouseButtonDown(0)) { var sp = Input.mousePosition; if (RectTransformUtility.RectangleContainsScreenPoint(this.transform as RectTransform, sp, CameraManager.uiCamera)) { overTime = Time.realtimeSinceStartup + 0.03f; } } if (Input.GetMouseButtonUp(0)) { var sp = Input.mousePosition; if (RectTransformUtility.RectangleContainsScreenPoint(this.transform as RectTransform, sp, CameraManager.uiCamera)) { if (Time.realtimeSinceStartup > overTime) { m_OnClick.Invoke(); overTime = float.MaxValue; } } } } } }