Ejemplo n.º 1
0
    public IEnumerator Fade(float direction, float duration, int type)
    {
        float t     = 0;
        float start = (direction + 1) / 2;

        while (t < duration)
        {
            t += Time.deltaTime;
            if (t > duration)
            {
                t = duration;
            }
            float alpha = 0;
            if (type == 0) //In
            {
                alpha = Easing.EaseInQuad(t, 0, 1, duration) * direction;
            }
            else if (type == 1) //Out
            {
                alpha = Easing.EaseOutQuad(t, 0, 1, duration) * direction;
            }
            else if (type == 2) //InOut
            {
                alpha = Easing.EaseInOutQuad(t, 0, 1, duration) * direction;
            }
            else if (type == 3)
            {
                alpha = Easing.EaseLinear(t, 0, 1, duration) * direction;
            }

            image.color = new Color(1, 1, 1, alpha);

            yield return(null);
        }
    }
Ejemplo n.º 2
0
    public IEnumerator MusicFade(float direction, float duration, int type)
    {
        float t     = 0;
        float start = music.volume;

        if (direction == 1)
        {
            music.Play();
        }


        while (t < duration)
        {
            t += Time.deltaTime;
            if (t > duration)
            {
                t = duration;
            }
            float x = 0;
            if (type == 0) //In
            {
                x = Easing.EaseInQuad(t, 0, 1, duration) * direction;
            }
            else if (type == 1) //Out
            {
                x = Easing.EaseOutQuad(t, 0, 1, duration) * direction;
            }
            else if (type == 2) //InOut
            {
                x = Easing.EaseInOutQuad(t, 0, 1, duration) * direction;
            }
            else if (type == 3)
            {
                x = Easing.EaseLinear(t, 0, 1, duration) * direction;
            }

            music.volume = start + x * maxVolume;
            yield return(null);
        }

        if (direction == -1)
        {
            music.Stop();
        }
        yield return(null);
    }