/// <summary> /// Create a Timer that ticks until some condition is met. /// The Timer returned by this instance will not execute until Timer.Do is called /// </summary> /// <param name="predicate">A function returning True or False - where True signifies that the Timer should end</param> /// <returns>A new Timer instance</returns> public static PulseTimer Until(PulseTimer.PulseValidator predicate) { if (_instance != null) { PulseTimer t = new PulseTimer(null); if (predicate != null) { t.Until(predicate); } _instance.Timers.Add(t); return(t); } else { throw new PulseException("No instance of Pulse could be found. Please make sure you have the Pulse component enabled in the scene."); } }
/// <summary> /// Create a Timer that ticks for the given number of repetitions. /// The Timer returned by this instance will not execute until Timer.Do is called /// </summary> /// <param name="repetitions">The number of reptitions</param> /// <returns>A new Timer instance</returns> public static PulseTimer For(int repetitions) { if (_instance != null) { if (repetitions >= 0) { PulseTimer t = new PulseTimer(null, repetitions); _instance.Timers.Add(t); return(t); } else { throw new PulseException("The number of repetitions must be greater than or equal to 0"); } } else { throw new PulseException("No instance of Pulse could be found. Please make sure you have the Pulse component enabled in the scene."); } }
/// <summary> /// Create a Timer that ticks regularly based on the given interval. /// The Timer returned by this instance will not execute until Timer.Do is called /// </summary> /// <param name="interval">The length of time, in seconds, between ticks</param> /// <returns>A new Timer instance</returns> public static PulseTimer Every(float interval) { if (_instance != null) { if (interval >= 0) { PulseTimer t = new PulseTimer(interval); _instance.Timers.Add(t); return(t); } else { throw new PulseException("Interval must be greater than or equal to 0"); } } else { throw new PulseException("No instance of Pulse could be found. Please make sure you have the Pulse component enabled in the scene."); } }