From 7b3f5234c60b74abedc0271f2357e66fcf2b999e Mon Sep 17 00:00:00 2001 From: koogelpotato <38011587+koogelpotato@users.noreply.github.com> Date: Mon, 28 Nov 2022 00:04:58 +0300 Subject: [PATCH] Gives the abillity to adjust the repeating timer adds more functionality --- Runtime/Components/Timers/TimerBehaviour.cs | 33 ++++++++------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/Runtime/Components/Timers/TimerBehaviour.cs b/Runtime/Components/Timers/TimerBehaviour.cs index 5b4f57c..5c5a5e5 100644 --- a/Runtime/Components/Timers/TimerBehaviour.cs +++ b/Runtime/Components/Timers/TimerBehaviour.cs @@ -3,32 +3,25 @@ namespace DapperDino.DapperTools.Components.Timers { - public class TimerBehaviour : MonoBehaviour + public class TimerComponent : MonoBehaviour { - [SerializeField] private float duration = 1f; - [SerializeField] private UnityEvent onTimerEnd = null; - - private Timer timer; + [SerializeField] private float _duration = 1f; + [SerializeField] private bool _isRepetitive = false; + [SerializeField] private UnityEvent _onTimerEnd = null; + private Timer _timer; private void Start() { - // Create a new timer and initialise it - timer = new Timer(duration); - - // Subscribe to the OnTimerEnd event to be able to handle that scenario - timer.OnTimerEnd += HandleTimerEnd; + _timer = new Timer(_duration, _isRepetitive); + _timer.OnTimerEnd += HandlerTimerEnd; } - - private void HandleTimerEnd() + private void HandlerTimerEnd() { - // Alert any listeners that the timer has ended - onTimerEnd.Invoke(); - - // Remove this component - // (Subject to change if I end up deciding that there is a better way to handle the timer ending) - Destroy(this); + _onTimerEnd?.Invoke(); + } + private void Update() + { + _timer.Tick(Time.deltaTime); } - - private void Update() => timer.Tick(Time.deltaTime); } }