Ludo-3D/Assets/Scripts/Input/TimerSystem.cs

63 lines
1.3 KiB
C#

using System;
public class TimerSystem
{
private float timeRem;
private float maxTimeAvail;
private Action onTimerComplete = null;
private Action onTimerInProgress = null;
public bool IsTimerComplete
{
get;
private set;
}
public bool IsInitialized
{
get;
private set;
}
public TimerSystem()
{
IsTimerComplete = false;
}
public void Init(float maxTimeAvail, Action onComplete = null, Action inProgress = null, Action onStart = null)
{
timeRem = 0;
IsTimerComplete = false;
IsInitialized = true;
this.maxTimeAvail = maxTimeAvail;
this.onTimerComplete = onComplete;
this.onTimerInProgress = inProgress;
}
public void UpdateTimer(float deltaTime)
{
if (timeRem < maxTimeAvail)
{
timeRem += deltaTime;
onTimerInProgress?.Invoke();
}
else
{
timeRem = 0;
onTimerComplete?.Invoke();
IsTimerComplete = true;
IsInitialized = false;
}
}
public void KillTimer()
{
timeRem = 0;
IsTimerComplete = true;
IsInitialized = false;
onTimerComplete = null;
onTimerInProgress = null;
}
}