using System; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace AX.Timer { public class Timer : IDisposable { private float sumTime; private float timer; private bool timerFlag; private bool isRepeat = false; private Action TimeOutEvent; public bool IsTimering { get { return timerFlag; } } public Timer(float timer) { sumTime = timer; //timerFlag = true; } public void AddTimeOutEvent(Action action) { TimeOutEvent += action; } public void UpdateTimer() { if (!timerFlag) return; timer += Time.deltaTime; if (timer >= sumTime) { if (TimeOutEvent != null) { TimeOutEvent(); } PauseTimer(); if (isRepeat) StartTimer(); } //Debug.Log(timer); } private void ResetTime() { timer = 0; } public void PauseTimer() { timerFlag = false; ResetTime(); } public void StartTimer() { timerFlag = true; ResetTime(); } public void StartTimerRepeat() { StartTimer(); isRepeat = true; } public int GetTimer() { return (int)timer; } public int GetRemainingTime() { return (int)(sumTime - timer); } public void Dispose() { TimeOutEvent = null; } } }