Пример #1
0
        static IEnumerator TweenSpriteAlphaRoutine(Sprite s, float from, float to, int duration, Easing.Equation easing,
                                                   int delay = 0, ITweener tweener = null)
        {
            if (delay > 0)
            {
                yield return(new WaitForMilliSeconds(delay));
            }

            float durationF = duration * 0.001f;
            float time      = 0;

            s.alpha = from;
            var childs = s.GetChildren();

            for (int i = 0; i < childs.Count; i++)
            {
                if (childs[i] is Sprite)
                {
                    ((Sprite)childs[i]).alpha = from;
                }
            }

            while (time < durationF)
            {
                s.alpha = Easing.Ease(easing, time, from, to, durationF);
                //Console.WriteLine($"{s.name} - alpha: {s.alpha}");

                for (int i = 0; i < childs.Count; i++)
                {
                    if (childs[i] is Sprite)
                    {
                        ((Sprite)childs[i]).alpha = Easing.Ease(easing, time, from, to, durationF);
                    }
                }

                time += Time.deltaTime * 0.001f;

                yield return(null);
            }

            if (tweener != null)
            {
                tweener.OnTweenEnd(s);
            }
        }