public Timer StartTimer(float timerLength, int loops, OnTimerComplete onComplete = null) { TimerLength = timerLength; Loops = loops; OnComplete = onComplete; Active = true; CurrentLoop = 0; ElapsedTime = 0f; return(this); }
protected override void Update() { if (IsRunning) { RemainingTime = System.Math.Max(0, RemainingTime - Application.Time.DeltaTime); OnTimerTick?.Invoke(this); if (RemainingTime == 0) { IsRunning = false; OnTimerComplete?.Invoke(this); } } }
public override void Update(float deltaTime) { if (IsRunning) { RemainingTime = Math.Max(0, RemainingTime - deltaTime); OnTimerTick?.Invoke(this); if (RemainingTime == 0) { IsRunning = false; OnTimerComplete?.Invoke(this); } } }
/// <summary> /// Updates the timer /// </summary> /// <param name="gameTime">The <see cref="GameTime"/> of the game</param> public void Update(GameTime gameTime) { if (ElapsedTime < Time) { ElapsedTime += gameTime.ElapsedGameTime.TotalSeconds; } else { OnTimerComplete?.Invoke(this, new EventArgs()); if (IsLooping) { ElapsedTime -= Time; } } }
public void SetOnCompleteCallback(OnTimerComplete callback) { onTimerComplete = callback; }
/// <summary> /// Runs the timer. /// </summary> /// <param name="_callback">Callback.</param> /// <param name="_sec">Sec.</param> /// <param name="_isLoop">If set to <c>true</c> is loop.</param> public void RunTimer(OnTimerComplete _callback, float _sec, bool _isLoop = false) { SetOnCompleteCallback(_callback); RunTimer(_sec, _isLoop); }