Beispiel #1
0
        private static IEnumerator TweenAlphaRoutine(Sprite sprite, float from, float to, int duration, int delay,
                                                     OnTweenComplete onComplete,
                                                     Easing.Equation equation)
        {
            //TODO: remove this call to WaitForMilliSeconds and implement it in the while loop to prevent another instantiation of a yield
            if (delay > 0)
            {
                yield return(new WaitForMilliSeconds(delay));
            }

            int time = 0;

            sprite.alpha = from;

            float fromDir = from > to ? from : 0;
            float toDir   = from > to ? 0 : from;

            while (time < duration)
            {
                sprite.alpha = toDir + Easing.Ease(equation, time, fromDir, to - from, duration);

                time += Time.deltaTime;
                yield return(null);
            }

            sprite.alpha = to;

            if (onComplete != null)
            {
                onComplete.Invoke(sprite);
            }
        }
Beispiel #2
0
        public static void TweenAlpha(Sprite sprite, float from, float to, int duration,
                                      OnTweenComplete onComplete = null, int delay = 0, Easing.Equation equation = Easing.Equation.QuadEaseOut)
        {
            if (_alphaRoutinesMap.ContainsKey(sprite))
            {
                CoroutineManager.StopCoroutine(_alphaRoutinesMap[sprite]);
                _alphaRoutinesMap.Remove(sprite);
            }

            var ie = CoroutineManager.StartCoroutine(
                TweenAlphaRoutine(sprite, from, to, duration, delay, onComplete, equation), null);

            _alphaRoutinesMap.Add(sprite, ie);
        }
Beispiel #3
0
        public static void TweenScalePingPong(Sprite sprite, float from, float to, int duration,
                                              OnTweenComplete onComplete = null, int delay = 0, Easing.Equation equation = Easing.Equation.QuadEaseOut)
        {
            if (sprite == null || sprite.Destroyed)
            {
                return;
            }

            SpriteTweener.TweenScale(sprite, from, to, duration, go =>
            {
                SpriteTweener.TweenScale(sprite, to, from, duration, go1 =>
                {
                    TweenScalePingPong(sprite, from, to, duration, null, delay, equation);
                });
            });
        }