AkiraPixelWind/Assets/Scripts/Main/UI/UIYYControl/UIButton.cs

73 lines
1.8 KiB
C#
Raw Normal View History

2022-12-29 18:20:40 +08:00
using Game;
using System.Collections;
using UnityEngine.EventSystems;
using UnityEngine;
namespace UnityEngine.UI
{
/// <summary>
/// UI button, 增加了CD功能, 默认开启CD, 默认CD 1s
/// </summary>
//[AddComponentMenu("UI/HY/UIButton", 301)]
[SerializeField]
public class UIButton : Button
{
[SerializeField, Tooltip("是否点击事件有冷却事件")]
private bool m_isCoolDown = true;
[SerializeField, Range(0f, 5.0f), Tooltip("冷却时长")]
private float m_clickSpace = 1.0f;
private bool m_isInCoolDown = false;
public bool mIsHSOW = false;
protected override void OnEnable()
{
base.OnEnable();
m_isInCoolDown = false;
}
public void SetClickSpace(float _space = 1.0f)
{
if (_space < 0.5f)
{
Debug.LogWarning("最小间隔0.5s");
return;
}
m_clickSpace = _space;
}
public override void OnPointerClick(PointerEventData eventData)
{
if (m_isCoolDown)
{
if (m_isInCoolDown)
{
//MessageRightLow.Instance.CreateTxt("操作太过频繁,请休息一会", Color.yellow);
GamePlayEntry.Tips.ShowHint("操作太过频繁,请休息一会", eHintType.Warn);
return;
}
}
StopCoroutine("ClickCoolDownCoroutine");
StartCoroutine("ClickCoolDownCoroutine");
base.OnPointerClick(eventData);
}
IEnumerator ClickCoolDownCoroutine()
{
m_isInCoolDown = true;
yield return new WaitForSeconds(m_clickSpace);
m_isInCoolDown = false;
}
}
}