#if HAVE_NODECANVAS
using System;
using UnityEngine;
using ParadoxNotion.Design;
using NodeCanvas.Framework;
namespace Framework.Support {
/// Ticks down a countdown timer in sync with in-game time passing
[Category("Utility")]
[Description("Ticks down a countdown timer until it reaches zero")]
public class TickDownRemainingTimeTask : ActionTask {
/// Remaining time counter that will be ticked down
[RequiredField]
public BBParameter RemainingTime;
/// Summary of what this action does
protected override string info {
get { return "Tick down " + this.RemainingTime.name; }
}
/// Called once when the action is executed
protected override void OnExecute() {
this.initialRemainingTime = this.RemainingTime.value;
this.gameTimeAtTaskStart = Time.time;
}
/// Called while the action is running
protected override void OnUpdate() {
if(this.RemainingTime.value > 0.0f) {
float passedTime = Time.time - this.gameTimeAtTaskStart;
this.RemainingTime.value = Mathf.Max(0.0f, this.initialRemainingTime - passedTime);
}
}
/// Remaining time when the task was entered
///
/// Instead of decrementing the remaining time by tiny amounts, we just remember
/// the initial value and calculate the entire remaining time from there to
/// avoid floating point issues if the game is running at very high frame rates.
///
private float initialRemainingTime;
/// Game time when the task started running
private float gameTimeAtTaskStart;
}
} // namespace Framework.Support
#endif // HAVE_NODECANVAS