using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;

[System.Serializable]
public class LongPressEvent : UnityEvent { }

//Author: SkyAllen Email: 894982165@qq.com Website: www.ytn0.com
public class LongPressButton : MonoBehaviour,IPointerDownHandler,IPointerUpHandler
{
    public LongPressEvent longPressEvent;

    private float timer = 0f;

    public float cd = 5f;

    public bool isPress = false;
    void Start()
    {
        
    }

    public void PrintMsg()
    {
        print("long press call");
    }

    
    void Update()
    {
        if (isPress)
        {
            timer += Time.deltaTime;
            if (timer > cd)
            {
                longPressEvent?.Invoke();
                timer = 0f;
            }
        }
    }

    public void OnPointerDown(PointerEventData eventData)
    {
        isPress = true;
    }

    public void OnPointerUp(PointerEventData eventData)
    {
        isPress = false;
        timer = 0f;
    }
}
