Files
UltimateFishing/Assets/Scripts/Assembly-CSharp/BitStrap/Timer.cs
2026-02-21 16:45:37 +08:00

90 lines
1.1 KiB
C#

using System;
using UnityEngine;
namespace BitStrap
{
[Serializable]
public class Timer
{
[SerializeField]
private float length = 1f;
private float counter = -1f;
private SafeAction onTimer = new SafeAction();
public float Length
{
get
{
return length;
}
set
{
length = value;
}
}
public SafeAction OnTimer
{
get
{
return onTimer;
}
}
public float RemainingTime
{
get
{
return (!(counter < 0f)) ? Mathf.Clamp(Length - counter, 0f, Length) : 0f;
}
}
public float Progress
{
get
{
return (!(counter < 0f)) ? Mathf.InverseLerp(0f, Length, counter) : 1f;
}
}
public bool IsRunning
{
get
{
return counter >= 0f;
}
}
public Timer(float length)
{
Length = length;
}
public void OnUpdate()
{
if (!(counter < 0f))
{
if (counter < Length)
{
counter += Time.deltaTime;
return;
}
counter = -1f;
OnTimer.Call();
}
}
public void Stop()
{
counter = -1f;
}
public void Start()
{
counter = 0f;
}
}
}