using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; using UnityEngine.EventSystems; /******************************************************************************* *Create By CG *Function image双击还是单击响应 *******************************************************************************/ namespace CG.UTility { public class ButtonExtension2 : MonoBehaviour, IPointerClickHandler { public float doubleClickIntervalTime = 0.25f; /// /// 双击 /// public UnityEvent onDoubleClick = new UnityEvent(); /// /// 点击 /// public UnityEvent onClick = new UnityEvent(); private float downTime = 0; private int clickTimes = 0; void Update() { if (clickTimes > 0) { downTime += Time.deltaTime; if (downTime > doubleClickIntervalTime) { clickTimes = 0; } } } public void OnPointerClick(PointerEventData eventData)//按键按下时调用 { if (clickTimes == 0) { onClick.Invoke(); clickTimes += 1; downTime = 0; } else { if (downTime <= doubleClickIntervalTime) { onDoubleClick.Invoke(); } } } } }