Exemple #1
0
        public IDisposable Subscribe(IObserver <float> observer)
        {
            var t = 0f;

            var disposable = new SingleAssignmentDisposable();

            disposable.Disposable = Observable.EveryUpdate().Subscribe(_ =>
            {
                t += Time.deltaTime / _duration;
                bool isCompleted = false;
                if (t >= 0.99999f)
                {
                    t           = 1f;
                    isCompleted = true;
                }

                try
                {
                    observer.OnNext(_easer?.Ease(t) ?? t);
                    if (isCompleted)
                    {
                        observer.OnCompleted();
                    }
                }
                finally
                {
                    if (isCompleted)
                    {
                        disposable.Dispose();
                    }
                }
            });

            return(disposable);
        }
Exemple #2
0
 /// <summary>
 /// Makes this easer animate backwards within the same time span
 /// </summary>
 public static IEaser Reversed(this IEaser This) =>
 new Easer(t => This.Ease(1 - t));
Exemple #3
0
 /// <summary>
 /// Eases this value using given easer
 /// </summary>
 public static float Ease(this float This, IEaser ease) =>
 ease.Ease(This);
Exemple #4
0
 /// <summary>
 /// Makes this easer animate forwards then backwards within the same time span
 /// </summary>
 public static IEaser PingPong(this IEaser This) =>
 new Easer(t => This.Ease(
               t <= 0.5f
                             ? t * 2
                             : 1 - (t - 0.5f) * 2));