Files
back_cantanBuilding/Assets/Scripts/UI/WaitingUI.cs
2026-05-26 16:15:54 +08:00

66 lines
1.4 KiB
C#

using System;
using UnityEngine;
namespace GameCore
{
public class WaitingUI : MonoBehaviour
{
public float Speed = 200;
public Action OnTimeOut;
float _timer;
float _rotZ;
bool _isTimeOutTriggered = false;
void OnEnable()
{
Trigger();
}
void Update()
{
if (_timer > 0f)
{
_timer -= Time.unscaledDeltaTime;
}
else
{
if (!_isTimeOutTriggered)
{
_isTimeOutTriggered = true;
OnTimeOut?.Invoke();
}
}
_rotZ -= Time.unscaledDeltaTime * Speed;
transform.rotation = Quaternion.Euler(0, 0, _rotZ);
}
void Trigger()
{
_timer = UIManager.TIME_OUT_MS * 0.001f;
_isTimeOutTriggered = false;
}
public void ResetTimeout(float time_out)
{
_timer = time_out;
}
// time_out_ms < 0 means keep showing and no time out trigger
public void Show(int time_out_ms)
{
if (time_out_ms > 0)
{
_timer = time_out_ms * 0.001f;
}
else
{
_timer = time_out_ms;
_isTimeOutTriggered = true; // Won't trigger time out event
}
}
}
}