/// <summary> /// Returns a new value based on the given values. /// Tweens the weight with the set sub curve. </summary> /// <param name="a"> the start value </param> /// <param name="b"> the end value </param> /// <param name="t"> the weight which lies between 0.0 and 1.0 </param> /// <returns> tweened value </returns> public virtual float Tween(float a, float b, float t) { t = TweenSub(0f, 1f, t); switch (Type) { case CurveType.Instant: return(a); case CurveType.Linear: return(Interpolator.Linear(a, b, t)); case CurveType.Quadratic: return(Interpolator.Quadratic(a, Interpolator.Linear(a, b, Constraints.C1), b, t)); case CurveType.Cubic: return(Interpolator.Cubic(a, Interpolator.Linear(a, b, Constraints.C1), Interpolator.Linear(a, b, Constraints.C2), b, t)); case CurveType.Quartic: return(Interpolator.Quartic(a, Interpolator.Linear(a, b, Constraints.C1), Interpolator.Linear(a, b, Constraints.C2), Interpolator.Linear(a, b, Constraints.C3), b, t)); case CurveType.Quintic: return(Interpolator.Quintic(a, Interpolator.Linear(a, b, Constraints.C1), Interpolator.Linear(a, b, Constraints.C2), Interpolator.Linear(a, b, Constraints.C3), Interpolator.Linear(a, b, Constraints.C4), b, t)); case CurveType.Bezier: float?cubicSolution = Calculator.SolveCubic(3f * (Constraints.C1 - Constraints.C3) + 1f, 3f * (Constraints.C3 - 2f * Constraints.C1), 3f * Constraints.C1, -t); if (cubicSolution == null) { cubicSolution = lastCubicSolution; } else { lastCubicSolution = cubicSolution.Value; } return(Interpolator.Linear(a, b, Interpolator.Bezier(cubicSolution.Value, 0f, Constraints.C2, Constraints.C4, 1f))); default: return(Interpolator.Linear(a, b, t)); } }