2025-01-02 12:15:45 +08:00

57 lines
1.5 KiB
C#

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;
/// <summary>
/// 双击
/// </summary>
public UnityEvent onDoubleClick = new UnityEvent();
/// <summary>
/// 点击
/// </summary>
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();
}
}
}
}
}