备份CatanBuilding瘦身独立工程
This commit is contained in:
65
Assets/Scripts/UI/WaitingUI.cs
Normal file
65
Assets/Scripts/UI/WaitingUI.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user