예제 #1
0
        // Do the fade
        IEnumerator DoFade(bool _in, float forceTime = -1f, System.Action onFinishFade = null)
        {
            // Initialize parameters
            var graphics = (fadeChildrens) ? GetComponentsInChildren <Graphic>() : GetComponents <Graphic>();
            var origin   = (_in) ? alphaLimits.x : alphaLimits.y;
            var target   = (_in) ? alphaLimits.y : alphaLimits.x;

            var time = (forceTime < 0) ? fadeTime : forceTime;

            // fade
            float counter = 0f;

            while (counter <= time)
            {
                var t = counter / time;
                for (int i = 0; i < graphics.Length; i++)
                {
                    var color = graphics[i].color;

                    color.a           = Mathf.Lerp(origin, target, Curves.ApplyCurve(t, smoothness));
                    graphics[i].color = color;
                }
                yield return(new WaitForEndOfFrame());

                counter += Time.deltaTime;
            }

            // Callbacks
            if (onFinishFade != null)
            {
                onFinishFade.Invoke();
            }
            onFinish.Invoke();
        }