Beispiel #1
0
        /// <summary>
        /// Calculate the new value using the Ease and Lerp functions
        /// </summary>
        /// <param name="start">Value to start at</param>
        /// <param name="end">Target Value</param>
        /// <param name="percent">Progress along ease function where 0-1 is 0%-100%</param>
        /// <param name="easeFunc">Function to use when Easing</param>
        /// <param name="lerpFunc">Function to use when Interpolating</param>
        /// <returns>Eased value</returns>
        private static T Calculate(T start, T end, float percent, EaseFunc easeFunc, LerpFunc <T> lerpFunc)
        {
            // Scale the percent based on the ease
            float scaledPercent = easeFunc(percent);

            // Pass in scaled percent to interpolation
            return(lerpFunc(start, end, scaledPercent));
        }
Beispiel #2
0
 public ChainItem(T destination, float duration, EaseFunc scaleFunc, TweenAccessors <T> accessors,
                  LerpFunc <T> lerp)
 {
     this.destination = destination;
     this.duration    = duration;
     this.scaleFunc   = scaleFunc;
     this.accessors   = accessors;
     this.lerpFunc    = lerp;
     this.tween       = new Tween <T>(this.lerpFunc);
 }
Beispiel #3
0
        public Tween(LerpFunc <T> lerp, T startValue, T endValue, float duration, Ease.EaseFunc easeFunc)
        {
            _lerp     = lerp;
            _duration = duration;
            _easeFunc = easeFunc;

            CurrentValue = startValue;
            StartValue   = startValue;
            EndValue     = endValue;

            State = TweenState.Stopped;
        }
Beispiel #4
0
        /// <summary>
        /// Create a new Tweener
        /// </summary>
        /// <param name="start">Value to start at</param>
        /// <param name="end">Target value</param>
        /// <param name="duration">Time (in seconds) to get to the target</param>
        /// <param name="easeFunc">Ease function to use (defaults to linear if unspecified)</param>
        /// <param name="lerpFunc">Lerp function to use (defaults to generic if unspecified)</param>
        public Tweener(T start, T end, double duration, EaseFunc easeFunc = null, LerpFunc <T> lerpFunc = null)
        {
            _elapsed  = 0.0f;
            _start    = start;
            _end      = end;
            _duration = duration;

            // If there's no ease function specified, use Linear
            _easeFunc = easeFunc ?? Ease.Linear;

            // If there's no lerp function specified, use Generic Default
            _lerpFunc = lerpFunc ?? LerpFuncDefault;

            Value   = _start;
            Running = true;
        }
Beispiel #5
0
        protected virtual LerpFunc <TValue> GetDefaultLerpFunc()
        {
            var type = typeof(TValue);

            if (type == typeof(float))
            {
                LerpFunc <float> lerpFunc = Tween1.LerpFloat;
                return((LerpFunc <TValue>)(object) lerpFunc);
            }
            if (type == typeof(Vector2))
            {
                LerpFunc <Vector2> lerpFunc = Vector2.Lerp;
                return((LerpFunc <TValue>)(object) lerpFunc);
            }
            if (type == typeof(Vector3))
            {
                LerpFunc <Vector3> lerpFunc = Vector3.Lerp;
                return((LerpFunc <TValue>)(object) lerpFunc);
            }
            return(null);
        }
 /// <summary>
 /// Initializes a new Tween with a given lerp function.
 /// </summary>
 /// <remarks>
 /// C# generics are good but not good enough. We need a delegate to know how to
 /// interpolate between the start and end values for the given type.
 /// </remarks>
 /// <param name="lerpFunc">The interpolation function for the tween type.</param>
 public Tween(LerpFunc <T> lerpFunc)
 {
     this.lerpFunc = lerpFunc;
     state         = TweenState.Stopped;
 }
Beispiel #7
0
 /// <summary>
 /// Create a new Tweener
 /// </summary>
 /// <param name="start">Value to start at</param>
 /// <param name="end">Target value</param>
 /// <param name="duration">Time (in seconds) to get to the target</param>
 /// <param name="easeFunc">Ease function to use (defaults to linear if unspecified)</param>
 /// <param name="lerpFunc">Lerp function to use (defaults to generic if unspecified)</param>
 public Tweener(T start, T end, float duration, EaseFunc easeFunc = null, LerpFunc <T> lerpFunc = null)
     : this(start, end, (double)duration, easeFunc, lerpFunc)
 {
 }
Beispiel #8
0
 /// <summary>
 /// Create a new Tweener
 /// </summary>
 /// <param name="start">Value to start at</param>
 /// <param name="end">Target value</param>
 /// <param name="duration">How long to get to the target</param>
 /// <param name="easeFunc">Ease function to use (defaults to linear if unspecified)</param>
 /// <param name="lerpFunc">Lerp function to use (defaults to generic if unspecified)</param>
 public Tweener(T start, T end, TimeSpan duration, EaseFunc easeFunc = null, LerpFunc <T> lerpFunc = null)
     : this(start, end, duration.TotalSeconds, easeFunc, lerpFunc)
 {
 }
        private static T EvaluateBezier <T>(float normalizedTime, T valueStart, T outValue, T inValue, T valueEnd, LerpFunc <T> lerp)
        {
            T t10 = lerp(valueStart, outValue, normalizedTime);
            T t11 = lerp(outValue, inValue, normalizedTime);
            T t12 = lerp(inValue, valueEnd, normalizedTime);
            T t20 = lerp(t10, t11, normalizedTime);
            T t21 = lerp(t11, t12, normalizedTime);

            return(lerp(t20, t21, normalizedTime));
        }
 private static T EvaluateLinear <T>(float normalizedTime, T valueStart, T valueEnd, LerpFunc <T> lerp)
 {
     return(lerp(valueStart, valueEnd, normalizedTime));
 }
Beispiel #11
0
 public TweenChainComponent AddTween <T>(T target, float duration, EaseFunc easeFunc, TweenAccessors <T> accessors,
                                         LerpFunc <T> lerp) where T : struct
 {
     this.chain.Append(new TweenChain.ChainItem <T>(target, duration, easeFunc, accessors, lerp));
     return(this);
 }
Beispiel #12
0
 public Tween()
 {
     LerpFunc = GetDefaultLerpFunc();
 }
Beispiel #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Channel{TValue}"/> class. Adds a Keyframe with a specific value and the right lerpFunction.
 /// </summary>
 /// <param name="lerpFunc">The right lerpfunction.</param>
 /// <param name="value">The value of the firs keyframe.</param>
 public Channel(LerpFunc lerpFunc, TValue value)
 {
     _lerpIt = lerpFunc;
     AddKeyframe(0, value);
 }
Beispiel #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Channel{TValue}"/> class. Adds the right Lerpfunction.
 /// </summary>
 /// <param name="lerpFunc">The right lerpfunction.</param>
 public Channel(LerpFunc lerpFunc)
 {
     _lerpIt = lerpFunc;
 }
Beispiel #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Channel{TValue}"/> class. Adds one default Keyframe and the right Lerpfunction.
 /// </summary>
 /// <param name="timeChanged">The time changed.</param>
 /// <param name="lerpFunc">The lerp function.</param>
 public Channel(SetChanelValue timeChanged, LerpFunc lerpFunc)
 {
     TimeChanged += timeChanged;
     _lerpIt      = lerpFunc;
     AddKeyframe(0, default(TValue));
 }