Exemple #1
0
        public void DoTransition(Action onOut, float duration, Color color, float durationOutPercent, Material mat)
        {
            if (canvas == null)
            {
                SetupCanvas();
            }

            mat.SetFloat(HASH_TRANSITION, 0f);

            var c0 = color;

            c0.a = 0f;


            image.material = mat;
            image.color    = color;
            canvas.enabled = true;

            float outDuration = duration * durationOutPercent;
            float inDuration  = duration * (1f - durationOutPercent);

            var fadeIn = new Animation <float>(val => mat.SetFloat(HASH_TRANSITION, val))
                         .From(1f).To(0f)
                         .For(inDuration)
                         .With(Interpolator.Decelerate())
                         .OnCompleted(() =>
            {
                canvas.enabled = false;
                //Destroy(mat);
            });

            mat.SetFloat(HASH_IN, 1f);

            var fadeOut = new Animation <float>(val => mat.SetFloat(HASH_TRANSITION, val))
                          .From(0f).To(1f)
                          .For(outDuration)
                          .With(Interpolator.Linear())
                          .OnCompleted(() =>
            {
                onOut?.Invoke();
                mat.SetFloat(HASH_IN, -1f);
                Conditional.WaitFrames(3).Do(() => { fadeIn.Start(); });
            })
                          .Start();
        }