Exemple #1
0
		void StartOnEnable () {
			if (!Enabled) {
				float time = Duration;
				#if QUARTER_TIME
				time *= 0.25f;
				#endif
				Co2.WaitForSeconds (time, () => {
					if (!perform)
						return;
					if (!Start ()) {
						StartOnEnable ();
					}
				});
			}
		}
Exemple #2
0
    /// <summary>
    /// Repeatedly invokes a function as long as the condition is met
    /// </summary>
    /// <param name="time">(optional) The initial delay before invoking begins</param>
    /// <param name="rate">The delay between invoke calls</param>
    /// <param name="condition">The expression to evaluate. When 'condition' is false, the coroutine stops.</param>
    /// <param name="onEnd">(optional) A function to run after the coroutine has finished</param>
    public static void InvokeWhileTrue(float time, float rate, Func <bool> condition, Action onInvoke, Action onEnd = null)
    {
        float duration = time > 0f ? time : rate;

        Co2.WaitForSeconds(duration, () => {
            if (condition())
            {
                onInvoke();
                InvokeWhileTrue(0f, rate, condition, onInvoke, onEnd);
            }
            else if (onEnd != null)
            {
                onEnd();
            }
        });
    }