前言
今天使用UGUI的知识来实现一下 按钮的双击和按钮长按的检测
其实我们的思路就是 每次按下检测按下时间 如果长按时间超过某一特定的值
那么我们判定 长按
至于双击的检测 我们是 当第一次按下之后抬起 开始计时 在特定值之前我们如果检测到按下第二次
我们判定双击按钮
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
public class ButtonExtension : MonoBehaviour, IPointerClickHandler, IPointerDownHandler, IPointerUpHandler, IPointerExitHandler
{
public float pressDurationTime = 1;
public bool responseOnceByPress = false;
public float doubleClickIntervalTime = 0.5f;
public UnityEvent onDoubleClick;
public UnityEvent onPress;
public UnityEvent onClick;
private bool isDown = false;
private bool isPress = false;
private float downTime = 0;