using System; using System.Collections.Generic; using UnityEngine; namespace coa4u { /// /// Interval action class for subclassing. /// public class ActionInterval : ActionInstant { protected float timer; protected float timeScale; private float dtrdata; public ActionInterval(float tgtDuration) : base() { duration = tgtDuration; timeScale = 1F; dtr = 0; } /// /// Returns a copy of the action. /// public override ActionInstant clone() { return new ActionInterval(duration); } /// /// Returns the reversed version of the action, if it is possible. /// public override ActionInstant reverse() { throw new Exception("Can reverse only the reversable interval actions"); } /// /// This method is called at the action start. /// public override void start() { base.start(); running = true; timer = 0F; } /// /// This method is called after the interval action is stopped. /// public override void stop() { base.stop(); running = false; } /// /// This method is called every frame update. Don't override this method, when inheriting, put your code in stepInterval instead. /// public override void step(float dt) { dt *= timeScale; base.step(dt); if (timer + dt > duration) { float odt = dt; dt = duration - timer; timer += odt; } else { timer += dt; } stepInterval(dt); if (timer > duration) { stop(); dtr = timer - duration; } } /// /// This method is called every frame update. Put your code here. /// public virtual void stepInterval(float dt) { } /// /// Immediately changes the time scale for this action and all nested ones. /// public void setTimeScale(float ts) { timeScale = ts; } } }