Unity UGUI Button 按下,抬起,连续按下,鼠标退出事件响应函数

来源:互联网 发布:Java swing黑色主题 编辑:程序博客网 时间:2024/06/10 01:40
using UnityEngine;  using UnityEngine.Events;  using UnityEngine.EventSystems;  using System.Collections;      public class test : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IPointerExitHandler, IPointerClickHandler  {      public float interval = 0.1f;          [SerializeField]      UnityEvent m_OnLongpress = new UnityEvent();      private bool isPointDown = false;      private float lastInvokeTime;          // Update is called once per frame      void Update()      {          if (isPointDown)          {              if (Time.time - lastInvokeTime > interval)              {                  //触发点击;                  m_OnLongpress.Invoke();                  lastInvokeTime = Time.time;                  Debug.Log("长按");              }          }      }          public void OnPointerDown(PointerEventData eventData)      {          m_OnLongpress.Invoke();              isPointDown = true;              lastInvokeTime = Time.time;          Debug.Log("鼠标按下");      }          public void OnPointerUp(PointerEventData eventData)      {          isPointDown = false;          Debug.Log("鼠标抬起");      }          public void OnPointerExit(PointerEventData eventData)      {          isPointDown = false;          Debug.Log("鼠标退出");      }      public void OnPointerClick(PointerEventData eventData)      {          isPointDown = false;          Debug.Log("鼠标点击");      }  }  

0 0
原创粉丝点击