Files
MinFt/Client/Assets/Scripts/UIExtend/LongPressOrClickTrigger.cs
Liubing\LB 3d8d4d18f3 first commit
先修复一下,错误的场景

删除不必要的钓场资产

修复into场景

update:更新meta文件,修复报错

update:修复资源

修复第一章节建造

修复建造第三章

update:删除多余内容

update:更新README.md

update:还原图标

update:更新README

update:更新配置
2026-04-28 02:17:22 +08:00

51 lines
1.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
public class LongPressOrClickTrigger : UIBehaviour, IPointerDownHandler, IPointerUpHandler
{
public UnityEvent onLongPress = new UnityEvent();
public UnityEvent onDown = new UnityEvent();
public UnityEvent onUp = new UnityEvent();
private bool isPointerDown = false;
private bool longPressTriggered = false;
private float timePressStarted;
/// <summary>指针在按钮上按下后至抬起前为 true划出按钮区域不中断与常见按住交互一致。</summary>
public bool IsPressing => isPointerDown;
private void Update()
{
if (isPointerDown && !longPressTriggered)
{
if (Time.time - timePressStarted > 0.2f)
{
onLongPress.Invoke();
longPressTriggered = true;
}
}
}
public void OnPointerDown(PointerEventData eventData)
{
timePressStarted = Time.time;
isPointerDown = true;
longPressTriggered = false;
onDown.Invoke();
}
public void OnPointerUp(PointerEventData eventData)
{
isPointerDown = false;
onUp.Invoke();
}
protected override void OnDisable()
{
base.OnDisable();
isPointerDown = false;
longPressTriggered = false;
}
}