using UnityEngine; using UnityEngine.Events; using UnityEngine.EventSystems; using System.Collections; using System;
/* * 长按按钮事件监听 */ public class DirectBtnController : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IPointerExitHandler { public float interval = 0.1f; [SerializeField] UnityEvent m_OnLongpress = new UnityEvent();//长按 private bool isPointDown = false; private float lastInvokeTime; void Start() { } void Update() { if (isPointDown) { if (Time.time - lastInvokeTime > interval) { //触发点击 do soemthing m_OnLongpress.Invoke(); lastInvokeTime = Time.time; Debug.Log("长按中..."); } } } public void OnPointerDown(PointerEventData eventData) { m_OnLongpress.Invoke(); isPointDown = true; lastInvokeTime = Time.time; } public void OnPointerExit(PointerEventData eventData) { isPointDown = false; } public void OnPointerUp(PointerEventData eventData) { isPointDown = false; } }
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号