Exemplo n.º 1
0
    static IEnumerator FadeNow(FadeParams p)
    {
        Image go = p.image;
        Text  t = p.txt;
        COL   c0 = p.c0, c1 = p.c1;
        float duration = p.duration;

        //start colours. 0 to 1.0
        float r = c0.r / 255.0f, g = c0.g / 255.0f, b = c0.b / 255.0f, a = c0.a / 255.0f;

        float dr, dg, db, da;     //deltas:0 to 1.0

        dr = (c1.r - c0.r) / 255.0f;
        dg = (c1.g - c0.g) / 255.0f;
        db = (c1.b - c0.b) / 255.0f;
        da = (c1.a - c0.a) / 255.0f;

        Color col = new Color();
        //print ("col-start");

        float timestart = Time.time;
        float timeend = timestart + duration;
        float timecur, percent;

        while (true)
        {
            timecur = Time.time;
            if (timecur > timeend)
            {
                break;
            }

            percent = (timecur - timestart) / duration;
            col.r   = Mathf.Clamp(r + percent * dr, 0.0f, 1.0f);
            col.g   = Mathf.Clamp(g + percent * dg, 0.0f, 1.0f);
            col.b   = Mathf.Clamp(b + percent * db, 0.0f, 1.0f);
            col.a   = Mathf.Clamp(a + percent * da, 0.0f, 1.0f);
            if (go != null)
            {
                go.color = col;
            }
            else
            {
                t.color = col;
            }
            yield return(new WaitForSeconds(0.01f));
        }

        //final fix bcos time might have elapsed and fade didnt complete
        if (go != null)
        {
            go.color = c1.toColor();
        }
        if (t != null)
        {
            t.color = c1.toColor();
        }

        //print ("col-end" + (Time.time - timestart));
    }