public static TweenRectMove moveRectFromTo(RectTransform rectTransform,
                                                   Func <Vector2> from,
                                                   Func <Vector2> to,
                                                   float duration           = 1f,
                                                   TweenEase easing         = null,
                                                   TweenStart onStart       = null,
                                                   TweenComplete onComplete = null,
                                                   TweenCancel onCancel     = null)
        {
            if (from == null)
            {
                throw new ArgumentNullException("from");
            }

            if (to == null)
            {
                throw new ArgumentNullException("to");
            }

            return(new TweenRectMove(rectTransform)
            {
                fromGetter = from,
                toGetter = to,
                easing = easing,
                duration = duration,
                externStart = onStart,
                externComplete = onComplete,
                externCancel = onCancel,
            });
        }
        public static TweenMove moveFromTo(Transform transform,
                                           Func <Vector3> from,
                                           Func <Vector3> to,
                                           float duration           = 1f,
                                           Space space              = Space.Self,
                                           TweenEase easing         = null,
                                           TweenStart onStart       = null,
                                           TweenComplete onComplete = null,
                                           TweenCancel onCancel     = null)
        {
            if (from == null)
            {
                throw new ArgumentNullException("from");
            }

            if (to == null)
            {
                throw new ArgumentNullException("to");
            }

            return(new TweenMove(transform)
            {
                fromGetter = from,
                toGetter = to,
                easing = easing,
                space = space,
                duration = duration,
                externStart = onStart,
                externComplete = onComplete,
                externCancel = onCancel,
            });
        }
Beispiel #3
0
    private IEnumerator Tween(MoveTweenData data, Action onComplete)
    {
        float     timer         = 0;
        float     duration      = data.Duration;
        TweenType tweenType     = data.TweenType;
        Vector3   startPosition = transform.position;
        Vector3   endPosition   = startPosition + data.EndPosition;
        Vector3   difference    = endPosition - startPosition;
        Vector3   newPosition   = startPosition;

        while (timer < duration)
        {
            // @TODO: Limit it only to necessary axis for performance.
            // For development purposes, all axis are available.

            newPosition.x      = TweenEase.GetNewValue(tweenType, timer, startPosition.x, difference.x, duration);
            newPosition.y      = TweenEase.GetNewValue(tweenType, timer, startPosition.y, difference.y, duration);
            newPosition.z      = TweenEase.GetNewValue(tweenType, timer, startPosition.z, difference.z, duration);
            transform.position = newPosition;
            timer = Mathf.Clamp(timer + Time.deltaTime, 0, duration);
            yield return(new WaitForEndOfFrame());
        }
        transform.position = endPosition;
        onComplete?.Invoke();
    }
        public static TweenEasing fromTo(Func <float> from,
                                         Func <float> to,
                                         float duration,
                                         TweenEase easing         = null,
                                         TweenUpdate onUpdate     = null,
                                         TweenStart onStart       = null,
                                         TweenComplete onComplete = null,
                                         TweenCancel onCancel     = null)
        {
            if (from == null)
            {
                throw new ArgumentNullException("from");
            }

            if (to == null)
            {
                throw new ArgumentNullException("to");
            }

            easing = easing ?? Easings.Linear;

            return(new TweenEasing
            {
                fromGetter = from,
                toGetter = to,
                easing = easing,
                duration = duration,
                externUpdate = onUpdate,
                externStart = onStart,
                externComplete = onComplete,
                externCancel = onCancel,
            });
        }
Beispiel #5
0
 private void Update()
 {
     if (_timer < _duration)
     {
         _currentValue = TweenEase.GetNewValue(_tweenType, _timer, _value, _value, _duration);
     }
     _timer = Mathf.Clamp(_timer + Time.deltaTime, 0, _duration);
 }
 public static TweenScale scaleFromTo(Transform transform,
                                      Vector3 from,
                                      Vector3 to,
                                      float duration           = 1f,
                                      TweenEase easing         = null,
                                      TweenStart onStart       = null,
                                      TweenComplete onComplete = null,
                                      TweenCancel onCancel     = null)
 {
     return(new TweenScale(transform)
     {
         from = from,
         to = to,
         easing = easing,
         duration = duration,
         externStart = onStart,
         externComplete = onComplete,
         externCancel = onCancel,
     });
 }
 public static TweenRectMove moveRectFromTo(RectTransform rectTransform,
                                            Vector2 from,
                                            Vector2 to,
                                            float duration           = 1f,
                                            TweenEase easing         = null,
                                            TweenStart onStart       = null,
                                            TweenComplete onComplete = null,
                                            TweenCancel onCancel     = null)
 {
     return(new TweenRectMove(rectTransform)
     {
         from = from,
         to = to,
         easing = easing,
         duration = duration,
         externStart = onStart,
         externComplete = onComplete,
         externCancel = onCancel,
     });
 }
        public static TweenScale scaleTo(Transform transform,
                                         Vector3 to,
                                         float duration           = 1f,
                                         TweenEase easing         = null,
                                         TweenStart onStart       = null,
                                         TweenComplete onComplete = null,
                                         TweenCancel onCancel     = null)
        {
            var tween = new TweenScale(transform)
            {
                to             = to,
                easing         = easing,
                duration       = duration,
                externStart    = onStart,
                externComplete = onComplete,
                externCancel   = onCancel,
            };

            tween.fromGetter = () => tween.transform.localScale;
            return(tween);
        }
        public static TweenRectMove moveRectTo(RectTransform rectTransform,
                                               Vector2 to,
                                               float duration           = 1f,
                                               TweenEase easing         = null,
                                               TweenStart onStart       = null,
                                               TweenComplete onComplete = null,
                                               TweenCancel onCancel     = null)
        {
            var tween = new TweenRectMove(rectTransform)
            {
                to             = to,
                easing         = easing,
                duration       = duration,
                externStart    = onStart,
                externComplete = onComplete,
                externCancel   = onCancel,
            };

            tween.fromGetter = () => tween.rectTransform.anchoredPosition;
            return(tween);
        }
 public static TweenRotate rotateFromTo(Transform transform,
                                        Quaternion from,
                                        Quaternion to,
                                        float duration           = 1f,
                                        Space space              = Space.Self,
                                        TweenEase easing         = null,
                                        TweenStart onStart       = null,
                                        TweenComplete onComplete = null,
                                        TweenCancel onCancel     = null)
 {
     return(new TweenRotate(transform)
     {
         from = from,
         to = to,
         easing = easing,
         space = space,
         duration = duration,
         externStart = onStart,
         externComplete = onComplete,
         externCancel = onCancel,
     });
 }
        public static TweenRotate rotateTo(Transform transform,
                                           Quaternion to,
                                           float duration           = 1f,
                                           Space space              = Space.Self,
                                           TweenEase easing         = null,
                                           TweenStart onStart       = null,
                                           TweenComplete onComplete = null,
                                           TweenCancel onCancel     = null)
        {
            var tween = new TweenRotate(transform)
            {
                to             = to,
                easing         = easing,
                space          = space,
                duration       = duration,
                externStart    = onStart,
                externComplete = onComplete,
                externCancel   = onCancel,
            };

            tween.fromGetter = () => transform.localRotation;
            return(tween);
        }
        public static TweenColorEasing fromTo(Color from,
                                              Color to,
                                              float duration,
                                              TweenEase easing          = null,
                                              ColorTweenUpdate onUpdate = null,
                                              TweenStart onStart        = null,
                                              TweenComplete onComplete  = null,
                                              TweenCancel onCancel      = null)
        {
            easing = easing ?? Easings.Linear;

            return(new TweenColorEasing
            {
                from = from,
                to = to,
                easing = easing,
                duration = duration,
                externUpdate = onUpdate,
                externStart = onStart,
                externComplete = onComplete,
                externCancel = onCancel,
            });
        }
        public static TweenMove moveTo(Transform transform,
                                       Vector3 to,
                                       float duration           = 1f,
                                       Space space              = Space.Self,
                                       TweenEase easing         = null,
                                       TweenStart onStart       = null,
                                       TweenComplete onComplete = null,
                                       TweenCancel onCancel     = null)
        {
            var tween = new TweenMove(transform)
            {
                to             = to,
                easing         = easing,
                duration       = duration,
                space          = space,
                externStart    = onStart,
                externComplete = onComplete,
                externCancel   = onCancel,
            };

            tween.fromGetter = () => tween.space == Space.Self ? tween.transform.localPosition : tween.transform.position;
            return(tween);
        }
Beispiel #14
0
 public static TweenNodule FloatTo(float p_startValue, float p_finalValue, float p_duration, TweenEase p_easeType, Action <float> p_callbackUpdate)
 {
     return(FloatTo(p_startValue, p_finalValue, p_duration, p_easeType, 0, p_callbackUpdate));
 }
Beispiel #15
0
        public static TweenNodule Vector4To(Vector4 p_startValue, Vector4 p_finalValue, float p_duration, TweenEase p_easeType, float p_delay, bool p_useUnityTime, Action <Vector4> p_callbackUpdate)
        {
            TweenNodule __temp = ATween.FloatTo(0, 1, p_duration, p_easeType, p_delay, p_useUnityTime, delegate(float newFloat)
            {
                p_callbackUpdate(Vector4.Lerp(p_startValue, p_finalValue, newFloat));
            });

            return(__temp);
        }
Beispiel #16
0
 public static TweenNodule Vector4To(Vector4 p_startValue, Vector4 p_finalValue, float p_duration, TweenEase p_easeType, float p_delay, Action <Vector4> p_callbackUpdate)
 {
     return(Vector4To(p_startValue, p_finalValue, p_duration, p_easeType, p_delay, true, p_callbackUpdate));
 }
Beispiel #17
0
        public static TweenNodule RectTo(Rect p_startValue, Rect p_finalValue, float p_duration, TweenEase p_easeType, float p_delay, bool p_useUnityTime, Action <Rect> p_callbackUpdate)
        {
            TweenNodule __temp = ATween.FloatTo(0, 1, p_duration, p_easeType, p_delay, p_useUnityTime, delegate(float newFloat)
            {
                p_callbackUpdate(new Rect(
                                     Mathf.Lerp(p_startValue.x, p_finalValue.x, newFloat),
                                     Mathf.Lerp(p_startValue.y, p_finalValue.y, newFloat),
                                     Mathf.Lerp(p_startValue.width, p_finalValue.width, newFloat),
                                     Mathf.Lerp(p_startValue.height, p_finalValue.height, newFloat)
                                     ));
            });

            return(__temp);
        }
Beispiel #18
0
 public static TweenNodule RectTo(Rect p_startValue, Rect p_finalValue, float p_duration, TweenEase p_easeType, float p_delay, Action <Rect> p_callbackUpdate)
 {
     return(RectTo(p_startValue, p_finalValue, p_duration, p_easeType, p_delay, true, p_callbackUpdate));
 }
Beispiel #19
0
        public static TweenNodule ColorTo(Color p_startColor, Color p_finalColor, float p_duration, TweenEase p_easeType, float p_delay, bool p_useUnityTime, Action <Color> p_callbackUpdate)
        {
            TweenNodule __temp = ATween.FloatTo(0, 1, p_duration, p_easeType, p_delay, p_useUnityTime, delegate(float newFloat)
            {
                p_callbackUpdate(Color.Lerp(p_startColor, p_finalColor, newFloat));
            });

            return(__temp);
        }
Beispiel #20
0
 public static TweenNodule ColorTo(Color p_startColor, Color p_finalColor, float p_duration, TweenEase p_easeType, float p_delay, Action <Color> p_callbackUpdate)
 {
     return(ColorTo(p_startColor, p_finalColor, p_duration, p_easeType, p_delay, true, p_callbackUpdate));
 }
Beispiel #21
0
        public static TweenNodule QuaternionTo(Quaternion p_startValue, Quaternion p_finalValue, float p_duration, TweenEase p_easeType, float p_delay, bool p_useUnityTime, Action <Quaternion> p_callbackUpdate)
        {
            TweenNodule nodule = ATween.FloatTo(0, 1, p_duration, p_easeType, p_delay, p_useUnityTime, delegate(float newFloat)
            {
                p_callbackUpdate(Quaternion.Lerp(p_startValue, p_finalValue, newFloat));
            });

            return(nodule);
        }
Beispiel #22
0
 public static TweenNodule QuaternionTo(Quaternion p_startValue, Quaternion p_finalValue, float p_duration, TweenEase p_easeType, float p_delay, Action <Quaternion> p_callbackUpdate)
 {
     return(QuaternionTo(p_startValue, p_finalValue, p_duration, p_easeType, p_delay, true, p_callbackUpdate));
 }
Beispiel #23
0
 public static float Lerp(float from, float to, float t, TweenEase easing)
 {
     return(easing(t, from, to - from, 1f));
 }
Beispiel #24
0
 public static TweenNodule FloatTo(float p_startValue, float p_finalValue, float p_duration, TweenEase p_easeType, float p_delay, bool p_useUnityTime, Action <float> p_callbackUpdate)
 {
     return(FloatTo(p_startValue, p_finalValue, p_duration, p_easeType, p_delay, p_useUnityTime, false, p_callbackUpdate));
 }
Beispiel #25
0
        private static TweenNodule FloatTo(float p_startValue, float p_finalValue, float p_duration, TweenEase p_easeType, float p_delay, bool p_useUnityTime, bool p_isLoop, Action <float> p_callbackUpdate)
        {
            TweenNodule __nodule = new TweenNodule();

            float __startValue    = p_startValue;
            float __counter       = 0f;
            float __timeNow       = Time.time;
            float __ableToStartIn = __timeNow + p_delay;

            __nodule.args   = new float[] { __counter };
            __nodule.onLoop = p_isLoop;

            if (p_useUnityTime)
            {
                __nodule.onResume += delegate()
                {
                    __nodule.args[1] = Time.realtimeSinceStartup;
                }
            }
            ;

            //Delegates the function that must be executed at each update
            __nodule.toDo += delegate()
            {
                if (__ableToStartIn <= Time.time)
                {
                    if (!__nodule.paused)
                    {
                        //Rescue variables from class
                        float ___counter = __nodule.args[0];

                        float __currentValue;

                        if (___counter < p_duration)
                        {
                            //Increment counter
                            if (!p_useUnityTime)
                            {
                                ___counter += Timer.realDeltaTime;
                            }
                            else
                            {
                                ___counter += Time.deltaTime;
                            }
                            float __normalizedTime = Mathf.Min(___counter / p_duration, 1f);

                            //Increment the returned value on callback depending on ease style
                            __currentValue = EaseMathsTween.GetTransaction(__startValue, p_finalValue, __normalizedTime, p_easeType);


                            //Call the callback
                            p_callbackUpdate(__currentValue);

                            //Save necessary vars into the class for further calculations
                            __nodule.args[0] = ___counter;
                        }
                        else
                        {
                            if (__nodule.onLoop)
                            {
                                __nodule.args[0] = 0;
                                __ableToStartIn  = Time.realtimeSinceStartup + p_delay;
                            }
                            else
                            {
                                __nodule.finished = true;
                            }
                        }
                    }
                }
            };

            CoreTween.aTweenInstance.AddNodule(__nodule);

            return(__nodule);
        }
Beispiel #26
0
 private void UpdateScaler(float timeLeft)
 {
     DifficultyScale = (int)TweenEase.GetNewValue(_tweenType, _gameTimer.Duration - timeLeft, _difficultyRange.x, _difficultyRange.y, _gameTimer.Duration);
 }
Beispiel #27
0
 public static float Lerp(float from, float to, float t, float duration, TweenEase easing)
 {
     return(easing(t, from, to - from, duration));
 }
        public static float GetTransaction(float start, float end, float normalizedTime, TweenEase ease)
        {
            switch (ease)
            {
            default:
            case TweenEase.LINEAR:
                return(Linear(start, end, normalizedTime));

            case TweenEase.SPRING:
                return(SpringEase(start, end, normalizedTime));

            case TweenEase.QUAD_IN:
                return(EaseInQuad(start, end, normalizedTime));

            case TweenEase.QUAD_OUT:
                return(EaseOutQuad(start, end, normalizedTime));

            case TweenEase.QUAD_IN_OUT:
                return(EaseInOutQuad(start, end, normalizedTime));

            case TweenEase.CUBIC_IN:
                return(EaseInCubic(start, end, normalizedTime));

            case TweenEase.CUBIC_OUT:
                return(EaseOutCubic(start, end, normalizedTime));

            case TweenEase.CUBIC_IN_OUT:
                return(EaseInOutCubic(start, end, normalizedTime));

            case TweenEase.BOUNCE_IN:
                return(EaseInBounce(start, end, normalizedTime));

            case TweenEase.BOUNCE_OUT:
                return(EaseOutBounce(start, end, normalizedTime));

            case TweenEase.ELASTIC_IN:
                return(EaseInElastic(start, end, normalizedTime));

            case TweenEase.ELASTIC_OUT:
                return(EaseOutElastic(start, end, normalizedTime));

            case TweenEase.ELASTIC_IN_OUT:
                return(EaseInOutElastic(start, end, normalizedTime));

            case TweenEase.QUART_IN:
                return(EaseInQuart(start, end, normalizedTime));

            case TweenEase.QUART_OUT:
                return(EaseOutQuart(start, end, normalizedTime));

            case TweenEase.QUART_IN_OUT:
                return(EaseInOutQuart(start, end, normalizedTime));

            case TweenEase.QUINT_IN:
                return(EaseInQuint(start, end, normalizedTime));

            case TweenEase.QUINT_OUT:
                return(EaseOutQuint(start, end, normalizedTime));

            case TweenEase.QUINT_IN_OUT:
                return(EaseInOutQuint(start, end, normalizedTime));

            case TweenEase.SINE_IN:
                return(EaseInSine(start, end, normalizedTime));

            case TweenEase.SINE_OUT:
                return(EaseOutSine(start, end, normalizedTime));

            case TweenEase.SINE_IN_OUT:
                return(EaseInOutSine(start, end, normalizedTime));

            case TweenEase.EXPO_IN:
                return(EaseInExpo(start, end, normalizedTime));

            case TweenEase.EXPO_OUT:
                return(EaseOutExpo(start, end, normalizedTime));

            case TweenEase.EXPO_IN_OUT:
                return(EaseInOutExpo(start, end, normalizedTime));

            case TweenEase.CIRC_IN:
                return(EaseInCirc(start, end, normalizedTime));

            case TweenEase.CIRC_OUT:
                return(EaseOutCirc(start, end, normalizedTime));

            case TweenEase.CIRC_IN_OUT:
                return(EaseInOutCirc(start, end, normalizedTime));

            case TweenEase.BACK_IN:
                return(EaseInBack(start, end, normalizedTime));

            case TweenEase.BACK_OUT:
                return(EaseOutBack(start, end, normalizedTime));

            case TweenEase.BACK_IN_OUT:
                return(EaseInOutBack(start, end, normalizedTime));
            }
        }