public static void Alpha(CanvasGroup canvasGrp, float start, float end, float duration,
                                 Easing.Type easingType = Easing.Type.Linear, Action callback = null)
        {
            Tweener tweener = canvasGrp.gameObject.AddComponent <Tweener>();

            tweener.TweenAlpha(canvasGrp, start, end, duration, easingType, callback);
        }
        IEnumerator COTransform(Transform trans, Ttype ttype, Vector3 aVec, Vector3 bVec, float duration, float delay,
                                Easing.Type easingType, Action callback)
        {
            yield return(new WaitForSeconds(delay));

            float countTime = 0;
            float perc      = 0;
            float progress  = 0;

            while (countTime < duration)
            {
                countTime += Time.deltaTime;
                if (countTime > duration)
                {
                    countTime = duration;
                    break;
                }
                perc     = countTime / duration;
                progress = Easing.GetEasingFunction(easingType, perc);
                SetPos(trans, ttype, Vector3.Lerp(aVec, bVec, progress));
                yield return(null);
            }
            SetPos(trans, ttype, bVec);
            if (callback != null)
            {
                callback();
            }
            Destroy(this);
        }
        public static void Color(Action <Color> target, Color start, Color end, float duration, float delay = 0,
                                 Easing.Type easingType = Easing.Type.Linear, Action callback = null)
        {
            Tweener tweener = new GameObject("Tweener").AddComponent <Tweener>();

            tweener.TweenColor(target, start, end, duration, delay, easingType, callback);
        }
    //------------------------------------------------------------------------------------------------------------
    IEnumerator COLerp(Easing.Type easingType, Action <Color> target, Color start, Color end, float duration, float delay, Action callback)
    {
        float          currentLerpTime = 0;
        float          perc            = 0;
        float          progress        = 0;
        WaitForSeconds wait            = new WaitForSeconds(delay);

        yield return(wait);

        while (currentLerpTime <= duration)
        {
            currentLerpTime += Time.deltaTime;
            if (currentLerpTime > duration)
            {
                currentLerpTime = duration;
                break;
            }

            perc     = currentLerpTime / duration;
            progress = Easing.GetEasingFunction(easingType, perc);
            target(Color.Lerp(start, end, progress));
            yield return(null);
        }

        if (callback != null)
        {
            callback();
        }
    }
        public static void Transform(Transform trans, Ttype ttype,
                                     Vector3 aVec, Vector3 bVec, float duration, float delay = 0,
                                     Easing.Type easingType = Easing.Type.Linear, Action callback = null)
        {
            Tweener tweener = trans.gameObject.AddComponent <Tweener>();

            tweener.TweenTransform(trans, ttype, aVec, bVec, duration, delay, easingType, callback);
        }
        public static void Transform(RectTransform rTrans, Rtype rtype,
                                     Vector2 aVec, Vector2 bVec, float duration, float delay = 0,
                                     Easing.Type easingType = Easing.Type.Linear, Action callback = null)
        {
            Tweener tweener = rTrans.gameObject.AddComponent <Tweener>();

            tweener.TweenTransform(rTrans, rtype, aVec, bVec, duration, delay, easingType, callback);
        }
Beispiel #7
0
        private static IObservable <float> Execute(
            GameObject gameObject, float start, float end, float duration, Easing.Type easeType, float delayBefore = 0, float delayAfter = 0)
        {
            var easingMethod = typeof(Easing).GetMethod(easeType.ToString());

            object[] methodParams = { 0, start, end - start, duration };

            return
                //Observable.Empty<double>()
                //.StartWith(() => Time.time)
                //.SelectMany(startTime => observable.Select(_ => Time.time - startTime))

                (gameObject.UpdateAsObservable()
                 .Select(_ => Time.deltaTime)
                 .Scan(0f, (a, b) => a + b)
                 .TakeWhile(elapsedTime => elapsedTime <= duration)
                 .Last()
                 .Select(currentTime =>
            {
                methodParams[0] = Math.Min(currentTime, duration);
                return Convert.ToSingle(easingMethod?.Invoke(null, methodParams));
            }));
        }
Beispiel #8
0
 public PrimitiveTween(float duration, Easing.Type ease, bool start = false, float delay = 0) : base(duration, ease, start, delay)
 {
 }
Beispiel #9
0
    public static void FadeOut(this Camera cam, float duration, Action oncomplete = null, Easing.Type easing = Easing.Type.CubicInOut)
    {
        CameraCircleFade cf = camFade(cam);

        cf.Tween(1.4f, 0f, duration, x => cf.radius = x, easing, oncomplete);
    }
Beispiel #10
0
        private static IObservable <float> Execute(float start, float end, float duration, Easing.Type easeType, float delayBefore, float delayAfter)
        {
            var easingMethod = typeof(Easing).GetMethod(easeType.ToString());

            object[] methodParams = { 0, start, end - start, duration };

            IEnumerator TweenEnumerator(IObserver <float> observer, CancellationToken ct)
            {
                if (delayBefore > 0)
                {
                    yield return(new WaitForSeconds(delayBefore));
                }

                if (ct.IsCancellationRequested)
                {
                    observer.OnCompleted();
                    yield break;
                }

                if (ct.IsCancellationRequested)
                {
                    observer.OnCompleted();
                    yield break;
                }

                float elapsedTime = 0;
                float p           = 0;

                while (elapsedTime < duration)
                {
                    if (ct.IsCancellationRequested)
                    {
                        observer.OnCompleted();
                        yield break;
                    }

                    elapsedTime    += Time.deltaTime;
                    methodParams[0] = Math.Min(elapsedTime, duration);
                    p = Convert.ToSingle(easingMethod?.Invoke(null, methodParams));;

                    observer.OnNext(p);

                    yield return(null);
                }

                if (delayAfter > 0)
                {
                    yield return(new WaitForSeconds(delayAfter));
                }

                observer.OnCompleted();
            }

            return(Observable.FromCoroutine <float>(TweenEnumerator));
        }
Beispiel #11
0
 public static void TweenTranfrom(this Transform trans, Ttype ttype, Easing.Type easingType,
                                  Vector3 aVec, Vector3 bVec, float duration, float delay = 0, Action callback = null)
 {
     TweenExtensions.Transform(trans, ttype, aVec, bVec, duration, delay, easingType, callback);
 }
    //------------------------------------------------------------------------------------------------------------
    IEnumerator COLerp(TransformType transformType, Easing.Type easingType, Transform myTransform, Vector2 start, Vector2 end, float duration, bool isLocal, float delay, Action callback)
    {
        float          currentLerpTime = 0;
        float          perc            = 0;
        float          progress        = 0;
        WaitForSeconds wait            = new WaitForSeconds(delay);

        yield return(wait);

        while (currentLerpTime <= duration)
        {
            currentLerpTime += Time.deltaTime;
            if (currentLerpTime > duration)
            {
                currentLerpTime = duration;
                break;
            }
            perc     = currentLerpTime / duration;
            progress = Easing.GetEasingFunction(easingType, perc);
            switch (transformType)
            {
            case TransformType.Position:
            {
                if (isLocal)
                {
                    myTransform.localPosition = Vector2.Lerp(start, end, progress);
                }
                else
                {
                    myTransform.position = Vector2.Lerp(start, end, progress);
                }
            }
            break;

            case TransformType.Rotation:
            {
                if (isLocal)
                {
                    myTransform.localEulerAngles = Vector2.Lerp(start, end, progress);
                }
                else
                {
                    myTransform.eulerAngles = Vector2.Lerp(start, end, progress);
                }
            }
            break;

            case TransformType.Scale:
            {
                myTransform.localScale = Vector2.Lerp(start, end, progress);
            }
            break;
            }
            yield return(null);
        }

        if (callback != null)
        {
            callback();
        }
    }
Beispiel #13
0
 public IntTween(int from, int to, float duration, Easing.Type ease, bool start = true, float delay = 0) : base(duration, ease, start, delay) => SetFromTo(from, to);
Beispiel #14
0
 public QuaternionTween(quaternion from, quaternion to, float duration, Easing.Type ease, bool start = true, float delay = 0) : base(duration, ease, start, delay) => SetFromTo(from, to);
Beispiel #15
0
 public static IObservable <Color> Play(Color start, Color end, float duration = 1, Easing.Type easeType = Easing.Type.Linear, float delayBefore = 0, float delayAfter = 0)
 => Execute(0, 1, duration, easeType, delayBefore, delayAfter).Select(t => Color.LerpUnclamped(start, end, t));
Beispiel #16
0
 public static IObservable <float> Play(float start, float end, float duration = 1, Easing.Type easeType = Easing.Type.Linear, float delayBefore = 0, float delayAfter = 0)
 => Execute(start, end, duration, easeType, delayBefore, delayAfter);
Beispiel #17
0
        public static IObservable <Vector3> MoveTo(this GameObject gameObject, Vector3 dest, float duration, Easing.Type easeType)
        {
            var start = gameObject.transform.position;

            return(Execute(gameObject, 0, 1, duration, easeType)
                   .Select(t => Vector3.LerpUnclamped(start, dest, t))
                   .Do(x => gameObject.transform.position = x));
        }
Beispiel #18
0
 public static IObservable <float> Ease(this GameObject gameObject, float startPoint, float endPoint, float duration, Easing.Type easeType = Easing.Type.Linear)
 => Execute(gameObject, startPoint, endPoint, duration, easeType);
Beispiel #19
0
 public static void TweenRectTrans(this RectTransform trans, Rtype rtype, Easing.Type easingType,
                                   Vector2 aVec, Vector2 bVec, float duration, float delay = 0, Action callback = null)
 {
     TweenExtensions.Transform(trans, rtype, aVec, bVec, duration, delay, easingType, callback);
 }
Beispiel #20
0
 protected Tween(float duration, Easing.Type ease, bool start = false, float delay = 0) : base(ease, start ? State.Running : State.Paused, duration, delay)
 {
 }
Beispiel #21
0
 public Float4Tween(float4 from, float4 to, float duration, Easing.Type ease, bool start = true, float delay = 0) : base(duration, ease, start, delay) => SetFromTo(from, to);
Beispiel #22
0
 public static IObservable <Quaternion> Play(Quaternion start, Quaternion end, float duration = 1, Easing.Type easeType = Easing.Type.Linear, float delayBefore = 0, float delayAfter = 0)
 => Execute(0, 1, duration, easeType, delayBefore, delayAfter).Select(t => Quaternion.LerpUnclamped(start, end, t));
Beispiel #23
0
 public SplineTween(Spline spline, float duration, Easing.Type ease, bool start = true, float delay = 0) : base(duration, ease, start, delay) => SetSpline(spline);
 //------------------------------------------------------------------------------------------------------------
 /// <summary>
 /// Lerp Vector2
 /// </summary>
 /// <param name="transformType">Position, Rotation, Scale</param>
 /// <param name="easingType">Make lerping more realistic by picking the right easing function</param>
 /// <param name="myTransform">Target transform</param>
 /// <param name="startPos">Vector2 Start Position</param>
 /// <param name="endPos">Vector2 End Position</param>
 /// <param name="duration">Lerp Time</param>
 /// <param name="isLocal">If you would like to lerp in local position, use true.</param>
 /// <param name="delay">Delay before function start</param>
 /// <param name="callback">Action call at the end of function</param>
 public void Lerp(TransformType transformType, Easing.Type easingType, Transform myTransform, Vector2 startPos, Vector2 endPos, float duration, bool isLocal, float delay, Action callback)
 {
     StartCoroutine(COLerp(transformType, easingType, myTransform, startPos, endPos, duration, isLocal, delay, callback));
 }
    //------------------------------------------------------------------------------------------------------------
    /// <summary>
    /// Lerp Color
    /// </summary>

    /* EX.
     * EZLerp.Instance.Lerp(
     *    Easing.Type.Linear,
     *    result => yourColor = result,
     *    Color.White,
     *    Color.Black,
     *    1,
     *    0,
     *    null
     * );
     */
    /// <param name="easingType">Make lerping more realistic by picking the right easing function</param>
    /// <param name="target">Target to lerp.</param>
    /// <param name="start">Start value</param>
    /// <param name="end">End value</param>
    /// <param name="duration">Lerp Time</param>
    /// <param name="delay">Delay before function start</param>
    /// <param name="callback">Action call at the end of function</param>
    public void Lerp(Easing.Type easingType, Action <Color> target, Color start, Color end, float duration, float delay = 0, Action callback = null)
    {
        StartCoroutine(COLerp(easingType, target, start, end, duration, delay, callback));
    }
Beispiel #26
0
 public static IObservable <Quaternion> TweenTo(this Quaternion start, Quaternion end, float duration = 1, Easing.Type easeType = Easing.Type.Linear, float delayBefore = 0, float delayAfter = 0)
 => TweenTo(start, end, duration, easeType, delayBefore, delayAfter);
Beispiel #27
0
 public static IObservable <Vector4> TweenTo(this Vector4 start, Vector4 end, float duration = 1, Easing.Type easeType = Easing.Type.Linear, float delayBefore = 0, float delayAfter = 0)
 => TweenTo(start, end, duration, easeType, delayBefore, delayAfter);
Beispiel #28
0
 public static void TweenAlpha(this CanvasGroup canvas, float start, float end, float time,
                               Easing.Type easingType = Easing.Type.Linear, Action callback = null)
 {
     TweenExtensions.Alpha(canvas, start, end, time, easingType, callback);
 }
    //------------------------------------------------------------------------------------------------------------
    /// <summary>
    /// Lerp Float
    /// </summary>

    /* EX.
     * EZLerp.Instance.Lerp(
     *    Easing.Type.Linear,
     *    result => yourFloat = result,
     *    0,
     *    100,
     *    1,
     *    0,
     *    null
     * );
     */
    /// <param name="easingType">Make lerping more realistic by picking the right easing function</param>
    /// <param name="target">Target to lerp</param>
    /// <param name="start">Start value</param>
    /// <param name="end">End value</param>
    /// <param name="duration">Lerp Time</param>
    /// <param name="delay">Delay before function start</param>
    /// <param name="callback">Action call at the end of function</param>
    public void Lerp(Easing.Type easingType, Action <float> target, float start, float end, float duration, float delay, Action callback)
    {
        StartCoroutine(COLerp(easingType, target, start, end, duration, delay, callback));
    }
Beispiel #30
0
 public static IObservable <Color> TweenTo(this Color start, Color end, float duration = 1, Easing.Type easeType = Easing.Type.Linear, float delayBefore = 0, float delayAfter = 0)
 => TweenTo(start, end, duration, easeType, delayBefore, delayAfter);