private IEnumerator AnimateWithRespectCoroutine(float fromValue, float toValue, Func <float> percentageFetcherFunction, Action <float> mutatorFunction, EasingCurve easingCurve) { float currentPercentage; do { currentPercentage = percentageFetcherFunction(); float newValue = easingCurve.Apply(fromValue, toValue, currentPercentage); mutatorFunction(newValue); yield return(null); } while (currentPercentage + float.Epsilon < 1); }
private IEnumerator AnimateOverTimeCoroutine(float fromValue, float toValue, float timeSpanSeconds, Action <float> mutatorFunction, EasingCurve easingCurve) { System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); float currentPercentage; do { currentPercentage = (stopwatch.ElapsedMilliseconds / 1000F) / timeSpanSeconds; float newValue = easingCurve.Apply(fromValue, toValue, currentPercentage); mutatorFunction(newValue); yield return(null); } while (currentPercentage + float.Epsilon < 1); }