Exemple #1
0
    public static Coroutine FloatFadeOut(this MonoBehaviour script, float fromValue, float toValue, float duration, ActionFloat update, UnityAction end = null)
    {
        FunctionFloat f = (t) =>
        {
            return(1f - Mathf.Pow(1f - t, 2f));
        };

        return(script.StartCoroutine(FloatFadeCoroutine(fromValue, toValue, duration, f, update, end)));
    }
Exemple #2
0
    public static Coroutine FloatFadeInOut(this MonoBehaviour script, float fromValue, float toValue, float duration, ActionFloat update, UnityAction end = null)
    {
        FunctionFloat f = (t) =>
        {
            float x = t * 2f - 1f;
            float y = Mathf.Sign(x) * Mathf.Pow(Mathf.Abs(x), 0.5f);
            return((y + 1f) * 0.5f);
        };

        return(script.StartCoroutine(FloatFadeCoroutine(fromValue, toValue, duration, f, update, end)));
    }
Exemple #3
0
    private static IEnumerator FloatFadeCoroutine(float fromValue, float toValue, float duration, FunctionFloat function, ActionFloat update, UnityAction end)
    {
        float t = 0f;

        while (t < 1f)
        {
            t += Time.deltaTime / duration; if (t > 1f)
            {
                t = 1f;
            }

            float value = Mathf.Lerp(fromValue, toValue, function(t));

            update(value);

            yield return(null);
        }

        if (end != null)
        {
            end.Invoke();
        }
    }