Beispiel #1
0
        public static void FrontToBack(ITweener tweener, int times)
        {
            TimesLoopingHelper helper = new TimesLoopingHelper(tweener, times);

            tweener.Ended -= helper.FrontToBack;
            tweener.Ended += helper.FrontToBack;
        }
        private void StartTweeners()
        {
            playingTweeners.Clear();
            playingTweeners.AddRange(tweeners);

            for (int i = playingTweeners.Count - 1; i >= 0; --i)
            {
                ITweener tweener = playingTweeners[i];

                tweener.TimeScale = TimeScale;
                tweener.SetEase(EaseFunction);

                tweener.Start();

                if (!tweener.IsPlaying)
                {
                    playingTweeners.RemoveAt(i);
                }
            }

            if (playingTweeners.Count == 0)
            {
                NewMarkCompleted();
            }
        }
Beispiel #3
0
        public static void BackAndForth(ITweener tweener, int times)
        {
            TimesLoopingHelper helper = new TimesLoopingHelper(tweener, times);

            tweener.Ended -= helper.BackAndForth;
            tweener.Ended += helper.BackAndForth;
        }
 public static void TweenColorAlpha(IHasColor hasColor, float from, float to, int duration,
                                    Easing.Equation easing,
                                    int delay = 0, ITweener tweener = null)
 {
     CoroutineManager.StartCoroutine(
         TweenColorAlphaRoutine(hasColor, from, to, duration, easing, delay, tweener), null);
 }
Beispiel #5
0
        private static Task <Completion> TestSteps <T>(ITweener t, Coroutines?cors, Func <T> value, T[] expected, Action <T, T> assertEq, bool lastIsComplete = true)
        {
            cors ??= new Coroutines();
            var tw = t.Run(cors);

            for (int ii = 0; ii < expected.Length; ++ii)
            {
                cors.Step();
                if (lastIsComplete && ii == expected.Length - 1)
                {
                    Assert.IsTrue(tw.IsCompleted);
                }
                else
                {
                    Assert.IsFalse(tw.IsCompleted);
                }
                try {
                    assertEq(value(), expected[ii]);
                } catch (Exception e) {
                    Console.WriteLine($"Failed steps comparison at index {ii}");
                    throw;
                }
            }
            return(tw);
        }
        protected override void OnTweenReset(bool kill, ResetMode resetMode)
        {
            for (int i = tweeners.Count - 1; i >= 0; --i)
            {
                ITweener tweener = tweeners[i];

                tweener.Reset(resetMode);
            }
        }
Beispiel #7
0
 private void OnAnimationCompleted(ITweener tweener)
 {
     if (tweener.IsCompleted)
     {
         CAAnimation am = (CAAnimation)tweener;
         AnimationDidStop?.Invoke(am, true);
         OnCompleted(am, true);
         Animations.Remove(am.ForKey);
     }
 }
        static IEnumerator TweenColorAlphaRoutine(IHasColor hasColor, 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;

            hasColor.Alpha = from;
            var childs = hasColor.children;

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

            while (time < durationF)
            {
                hasColor.Alpha = Easing.Ease(easing, time, from, to, durationF);

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

                time += Time.deltaTime * 0.001f;

                yield return(null);
            }

            hasColor.Alpha = to;
            for (int i = 0; i < childs.Count; i++)
            {
                if (childs[i] is IHasColor)
                {
                    ((IHasColor)childs[i]).Alpha = to;
                }
            }

            if (tweener != null)
            {
                tweener.OnTweenEnd(hasColor);
            }
        }
Beispiel #9
0
 public void Init(TweenTime timeProvider, TweenBuilder builder)
 {
     this.timeProvider = timeProvider;
     this.tweener      = builder.Tweener;
     this.easeType     = builder.EaseType;
     this.tweenType    = builder.TweenType;
     this.easeFunction = builder.EaseFunction;
     this.duration     = builder.Duration;
     this.delayTime    = builder.Delay;
     this.handler      = builder.Handler;
     this.startTime    = 0;
     this.realTime     = 0;
     this.pauseTime    = 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);
            }
        }
        protected override void OnTweenUpdate()
        {
            for (int i = playingTweeners.Count - 1; i >= 0; --i)
            {
                ITweener tweener = playingTweeners[i];

                tweener.Update();

                if (!tweener.IsPlaying)
                {
                    playingTweeners.RemoveAt(i);
                }
            }

            if (playingTweeners.Count == 0)
            {
                NewMarkCompleted();
            }
        }
Beispiel #12
0
    void BounceDone(ITweener tw)
    {
        tw.SetOnFinishedDelegate(null);
        if (IsActive)
        {
            IsActive = loopBounce && gameObject.activeSelf && gameObject.activeInHierarchy;
            if (IsActive)
            {
                tw.SetBeginStateImmediately();
                float newMiddleDelay = middleDelay + (randomMiddleDelay ? (middleDelay * Random.Range(-randomMiddleDelayPercent, randomMiddleDelayPercent) / 100f) : 0f);

                if (bounceSessionTime > 0 && sessionTime > bounceSessionTime)
                {
                    sessionTime     = -bounceSessionDelay;
                    newMiddleDelay += bounceSessionDelay;
                }

                tw.SetEndState(newMiddleDelay, BounceDone);
            }
        }
    }
        public void Add(ITweener tweener)
        {
            if (tweener == null)
            {
                throw new ArgumentNullException($"Tried to {nameof(Add)} a null {nameof(ITweener)} on {nameof(InterpolationTween)}");
            }

            if (tweener.IsPlaying)
            {
                throw new ArgumentNullException($"Tried to {nameof(Add)} a {nameof(ITweener)} on {nameof(InterpolationTween)} " +
                                                $"but it was already playing");
            }

            if (tweeners.Contains(tweener))
            {
                throw new ArgumentNullException($"Tried to {nameof(Add)} a {nameof(ITweener)} on {nameof(InterpolationTween)} " +
                                                $"but it was already added");
            }

            tweeners.Add(tweener);

            durationCalculated = false;
        }
Beispiel #14
0
 public static void BackAndForth(ITweener tweener)
 {
     tweener.Ended += tweener.Reverse;
 }
 public static void TweenColorAlpha(IHasColor hasColor, float from, float to, int duration, ITweener tweener)
 {
     TweenColorAlpha(hasColor, from, to, duration, Easing.Equation.Linear, 0, tweener);
 }
 public void SetUp()
 {
     tweener = new ColorTweener(Linear.EaseNone);
 }
Beispiel #17
0
 internal void RemoveTweener(ITweener tweener)
 {
     RemoveTweener(tweenerUpdate.IndexOf(tweener));
 }
Beispiel #18
0
 internal LoopHelper(ITweener tweener)
 {
     this.tweener = tweener;
 }
Beispiel #19
0
 public static void BackAndForth(ITweener tweener)
 {
     tweener.Ended -= tweener.Reverse;
     tweener.Ended += tweener.Reverse;
 }
Beispiel #20
0
 /// <summary>
 /// MonoBehaviour Awake callback.
 /// </summary>
 protected virtual void Awake()
 {
     tweener = AnimationManager.Instance.Configuration.Tweener;
 }
 public static void TweenSpriteAlpha(Sprite s, float from, float to, int duration, ITweener tweener)
 {
     TweenSpriteAlpha(s, from, to, duration, Easing.Equation.Linear, 0, tweener);
 }
Beispiel #22
0
 public static void FrontToBack(ITweener tweener, int times)
 {
     TimesLoopingHelper helper = new TimesLoopingHelper(tweener, times);
     tweener.Ended += helper.FrontToBack;
 }
 public static void TweenSpriteAlpha(Sprite s, float from, float to, int duration, Easing.Equation easing,
                                     int delay = 0, ITweener tweener = null)
 {
     CoroutineManager.StartCoroutine(TweenSpriteAlphaRoutine(s, from, to, duration, easing, delay, tweener), null);
 }
Beispiel #24
0
 public static void BackAndForth(ITweener tweener, int times)
 {
     TimesLoopingHelper helper = new TimesLoopingHelper(tweener, times);
     tweener.Ended += helper.BackAndForth;
 }
 public StartableTweener(ITweener implementation, MonoBehaviour gameObject)
 {
     Implementation = implementation;
     GameObject     = gameObject;
 }
Beispiel #26
0
    void Update()
    {
        float delta = ignoreTimeScale ? Time.unscaledDeltaTime : Time.deltaTime;
        float time  = ignoreTimeScale ? Time.unscaledDeltaTime : Time.time;

        if (!mStarted)
        {
            delta      = 0;
            mStarted   = true;
            mStartTime = time + delay;
        }

        if (time < mStartTime)
        {
            return;
        }

        mFactor += (duration == 0f) ? 1f : amountPerDelta * delta;

        if (style == Style.Loop)
        {
            if (mFactor > 1f)
            {
                mFactor -= Mathf.Floor(mFactor);
            }
        }
        else if (style == Style.PingPong)
        {
            if (mFactor > 1f)
            {
                mFactor         = 1f - (mFactor - Mathf.Floor(mFactor));
                mAmountPerDelta = -mAmountPerDelta;
            }
            else if (mFactor < 0f)
            {
                mFactor         = -mFactor;
                mFactor        -= Mathf.Floor(mFactor);
                mAmountPerDelta = -mAmountPerDelta;
            }
        }

        if ((style == Style.Once) && (duration == 0f || mFactor > 1f || mFactor < 0f))
        {
            mFactor = Mathf.Clamp01(mFactor);
            Sample(mFactor, true);
            enabled = false;

            if (current != this)
            {
                ITweener before = current;
                current = this;

                if (onFinished != null)
                {
                    for (int i = 0; i < onFinished.Count; ++i)
                    {
                        FinishedEvent ed = onFinished[i];
                        if (ed != null)
                        {
                            ed();
                        }
                    }
                }
                current = before;
            }
        }
        else
        {
            Sample(mFactor, false);
        }
    }
Beispiel #27
0
 public TweenBuilder WithTweener(ITweener accessor)
 {
     this.tweener = accessor;
     return(this);
 }
Beispiel #28
0
 internal void AddTweener(ITweener tweener)
 {
     tweenerUpdate.Add(tweener);
 }
Beispiel #29
0
 public static void FrontToBack(ITweener tweener)
 {
     tweener.Ended += tweener.Restart;
 }
Beispiel #30
0
 public static void FrontToBack(ITweener tweener)
 {
     tweener.Ended += tweener.Restart;
 }
Beispiel #31
0
 public static void BackAndForth(ITweener tweener)
 {
     tweener.Ended += delegate { tweener.Reverse(); };
 }
Beispiel #32
0
 public static void BackAndForth(ITweener tweener)
 {
     tweener.Ended += delegate { tweener.Reverse(); };
 }
Beispiel #33
0
 public TimesLoopingHelper(ITweener tweener, int times)
 {
     this.tweener = tweener;
     this.times = times;
 }
Beispiel #34
0
 public TimesLoopingHelper(ITweener tweener, int times)
 {
     this.tweener = tweener;
     this.times   = times;
 }