//-------------------------------------------------------- 
 | 
//    [Author]:           玩个游戏 
 | 
//    [  Date ]:           Saturday, November 25, 2017 
 | 
//-------------------------------------------------------- 
 | 
using UnityEngine; 
 | 
using System.Collections; 
 | 
using UnityEngine.UI; 
 | 
using UnityEngine.Events; 
 | 
using System; 
 | 
  
 | 
    [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; 
 | 
        Action m_OnClick; 
 | 
  
 | 
        public void AddListener(Action _callBack) 
 | 
        { 
 | 
            m_OnClick += _callBack; 
 | 
        } 
 | 
  
 | 
        public void RemoveAllListeners() 
 | 
        { 
 | 
            m_OnClick = null; 
 | 
        } 
 | 
  
 | 
        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; 
 | 
                    } 
 | 
                } 
 | 
            } 
 | 
        } 
 | 
  
 | 
    } 
 |