public static int RandomWithTarget(int min, int max, int target, EasingMethod lowEasingMethod, EasingMethod highEasingMethod) { if (min > target || target > max) { Debug.LogError("[NotSoRandom].RandomWithTarget(int) Invalid arguments. (" + min + ", " + max + ", " + target + ")\n" + System.Environment.StackTrace); } // ensure valid numbers if (min > target) { target = min; } if (max < target) { target = max; } int low = target - min; int high = max - target; float lowRand = Random.value; float highRand = Random.value; float lowRandEased = lowEasingMethod(lowRand); float highRandEased = highEasingMethod(highRand); float lowPortion = lowRandEased * low; float highPortion = highRandEased * high; int lowRounded = Mathf.RoundToInt(lowPortion); int highRounded = Mathf.RoundToInt(highPortion); return(min + lowRounded + highRounded); }
public static float RandomWithTarget(float min, float max, float target, EasingMethod lowEasingMethod, EasingMethod highEasingMethod) { if ((min > target && !Mathf.Approximately(min, target)) || (target > max && !Mathf.Approximately(max, target))) { Debug.LogError("[NotSoRandom].RandomWithTarget(float) Invalid arguments. (" + min + ", " + max + ", " + target + ")\n" + System.Environment.StackTrace); } // ensure valid numbers and fix floating point rounding errors if (min > target) { target = min; } if (max < target) { target = max; } float low = target - min; float high = max - target; float lowRand = Random.value; float highRand = Random.value; float lowRandEased = lowEasingMethod(lowRand); float highRandEased = highEasingMethod(highRand); float lowPortion = lowRandEased * low; float highPortion = highRandEased * high; return(min + lowPortion + highPortion); }
/// <summary> /// Tween /// </summary> /// <param name="method">Tweening method</param> /// <param name="t">Time (0..1)</param> /// <param name="b">Start value</param> /// <param name="c">Delta value</param> /// <returns>tweened value</returns> public static float Ease(EasingMethod method, float t, float b, float c) { switch (method) { case EasingMethod.ExponentialIn: return ExpoIn(t, b, c); case EasingMethod.ExponentialOut: return ExpoOut(t, b, c); case EasingMethod.ExponentialInOut: return ExpoInOut(t, b, c); case EasingMethod.ExponentialOutIn: return ExpoOutIn(t, b, c); case EasingMethod.CircularIn: return CircIn(t, b, c); case EasingMethod.CircularOut: return CircOut(t, b, c); case EasingMethod.CircularInOut: return CircInOut(t, b, c); case EasingMethod.CircularOutIn: return CircOutIn(t, b, c); case EasingMethod.QuadraticIn: return QuadIn(t, b, c); case EasingMethod.QuadraticOut: return QuadOut(t, b, c); case EasingMethod.QuadraticInOut: return QuadInOut(t, b, c); case EasingMethod.QuadraticOutIn: return QuadOutIn(t, b, c); case EasingMethod.SinusIn: return SineIn(t, b, c); case EasingMethod.SinusOut: return SineOut(t, b, c); case EasingMethod.SinusInOut: return SineInOut(t, b, c); case EasingMethod.SinusOutIn: return SineOutIn(t, b, c); case EasingMethod.CubicIn: return CubicIn(t, b, c); case EasingMethod.CubicOut: return CubicOut(t, b, c); case EasingMethod.CubicInOut: return CubicInOut(t, b, c); case EasingMethod.CubicOutIn: return CubicOutIn(t, b, c); case EasingMethod.QuarticIn: return QuartIn(t, b, c); case EasingMethod.QuarticOut: return QuartOut(t, b, c); case EasingMethod.QuarticInOut: return QuartInOut(t, b, c); case EasingMethod.QuarticOutIn: return QuartOutIn(t, b, c); case EasingMethod.QuinticIn: return QuintIn(t, b, c); case EasingMethod.QuinticOut: return QuintOut(t, b, c); case EasingMethod.QuinticInOut: return QuintInOut(t, b, c); case EasingMethod.QuinticOutIn: return QuintOutIn(t, b, c); default: return Linear(t, b, c); } }
//Easing on vector public static Vector3 vectorEasing(Vector3 _from, Vector3 _to, float _currentTime, float _duration, EasingMethod _easingMethod) { float x = _easingMethod(_currentTime, _from.x, _to.x, _duration); float y = _easingMethod(_currentTime, _from.y, _to.y, _duration); float z = _easingMethod(_currentTime, _from.z, _to.z, _duration); return new Vector3(x, y, z); }
public static Vector2 EaseVector2(EasingMethod method, Vector2 start, Vector2 end, float value) { Vector2 returnVec; returnVec.x = method(start.x, end.x, value); returnVec.y = method(start.y, end.y, value); return returnVec; }
static Vector3 easing_vector3(Vector3 from, Vector3 to, float t, EasingMethod method) { t = Mathf.Clamp(t, 0.0f, 1.0f); return(new Vector3( method(from.x, to.x, t), method(from.y, to.y, t), method(from.z, to.z, t))); }
public static Vector2 EaseVector2(EasingMethod method, Vector2 start, Vector2 end, float value) { Vector2 returnVec = new Vector2(); returnVec.x = method(start.x, end.x, value); returnVec.y = method(start.y, end.y, value); return(returnVec); }
public static Vector3 EaseVector3(EasingMethod method, Vector3 start, Vector3 end, float value) { Vector3 returnVec = new Vector3(); returnVec.x = method(start.x, end.x, value); returnVec.y = method(start.y, end.y, value); returnVec.z = method(start.z, end.z, value); return(returnVec); }
/// <summary> /// Initializes a new instance of the <see cref="ValueProvider{T}"/> class. /// </summary> /// <param name="startValue">The start value.</param> /// <param name="valueFactory">The value factory.</param> /// <param name="easingMethod">The easing method.</param> public ValueProvider(T startValue, ValueFactory <T> valueFactory, EasingMethod easingMethod) { this.StartValue = startValue; this.TargetValue = this.StartValue; this.StartTime = DateTime.Now; this.Duration = TimeSpan.Zero; this.EasingMethod = easingMethod; this.ValueFactory = valueFactory; }
public static Vector3 EaseVector3(EasingMethod method, Vector3 start, Vector3 end, float value) { Vector3 returnVec = new Vector3(); returnVec.x = method(start.x, end.x, value); returnVec.y = method(start.y, end.y, value); returnVec.z = method(start.z, end.z, value); return returnVec; }
public static float Ease(double linearStep, EasingType type, EasingMethod method) { switch (method) { case EasingMethod.Ease: return(Ease(linearStep, 0, type)); case EasingMethod.EaseIn: return(EaseIn(linearStep, type)); case EasingMethod.EaseOut: return(EaseOut(linearStep, type)); case EasingMethod.EaseInOut: return(EaseInOut(linearStep, type)); } throw new Exception("EasingMethod not found"); }
private static T GenerateEasingType <T>(EasingMethod easingMethod, bool enableIn, bool enableOut, EasingTypeConverter <T> converter, T defaultValue = default) { if (easingMethod > EasingMethod.None && easingMethod <= LastEasingMethod) { if (enableIn || enableOut) { return(converter(easingMethod, enableIn, enableOut)); } else { throw new ArgumentException("The easing in and out parameters were both false which is invalid."); } } else if (easingMethod == EasingMethod.None) { return(defaultValue); } else { throw new ArgumentException("The easing type value was beyond the easing type range."); } }
public EaseAnimation Tween(double startValue, double changeInValue, double duration, EasingMethod method) { var nanim = new EaseAnimation(EaseFuncs[method], startValue, changeInValue, duration); CurrentAnimations.Add(nanim); return(nanim); }
// Helper that constructs InOut form In and Out public static float InOut(EasingMethod In, EasingMethod Out, float position) { if (position <= 0.5f) { return In(position * 2f) / 2f; } else { return Out(2f * position - 1f) / 2f + 0.5f; } }
private static EasingType EasingToEasingType(EasingMethod easingMethod, bool enableIn, bool enableOut) => (EasingType)(1 << ((int)easingMethod + 3)) | (enableIn ? EasingType.In : EasingType.None) | (enableOut ? EasingType.Out : EasingType.None);
private static int EasingToEasingValue(EasingMethod easingMethod, bool enableIn, bool enableOut) => ((int)easingMethod - 1) * 3 + 1 + (enableIn ? 0 : 2) + (enableOut ? 0 : 1);
/// <summary>Generates an <seealso cref="EasingType"/> from the easing type properties.</summary> /// <param name="easingMethod">The easing method.</param> /// <param name="enableIn">Determines whether the easing will be applied at the start of the transformation.</param> /// <param name="enableOut">Determines whether the easing will be applied at the end of the transformation.</param> public static EasingType GenerateEasingType(EasingMethod easingMethod, bool enableIn, bool enableOut) => GenerateEasingType(easingMethod, enableIn, enableOut, EasingToEasingType);
/// <summary>Generates an <seealso cref="Easing"/> from the easing type properties.</summary> /// <param name="easingMethod">The easing method.</param> /// <param name="enableIn">Determines whether the easing will be applied at the start of the transformation.</param> /// <param name="enableOut">Determines whether the easing will be applied at the end of the transformation.</param> public static Easing GenerateEasing(EasingMethod easingMethod, bool enableIn, bool enableOut) => (Easing)GenerateEasingType(easingMethod, enableIn, enableOut, EasingToEasingValue);
/// <summary> /// Chains the two specified easing methods. /// </summary> /// <param name="first">The first easing method.</param> /// <param name="second">The second easing method.</param> /// <returns>An easing method that uses the first specified easing method for the first half of the animation and the second one for the second half of the animation.</returns> public static EasingMethod Chain(this EasingMethod first, EasingMethod second) { return (double progress) => (progress < 0.5) ? .5 * first(progress * 2) : .5 + .5 * second((progress - .5) * 2); }
/// <summary> /// Creates an upside down version of the specified easing method. /// </summary> /// <param name="method">The easing method.</param> /// <returns>An upside down version of the specified easing method</returns> public static EasingMethod UpsideDown(this EasingMethod method) { return((double progress) => 1 - method(progress)); }
/// <summary> /// Chains the two specified easing methods. /// </summary> /// <param name="first">The first easing method.</param> /// <param name="second">The second easing method.</param> /// <returns>An easing method that uses the first specified easing method for the first half of the animation and the second one for the second half of the animation.</returns> public static EasingMethod Chain(this EasingMethod first, EasingMethod second) { return((double progress) => (progress < 0.5) ? .5 * first(progress * 2) : .5 + .5 * second((progress - .5) * 2)); }
/// <summary> /// Tween /// </summary> /// <param name="method">Tweening method</param> /// <param name="t">Time (0..1)</param> /// <param name="b">Start value</param> /// <param name="c">Delta value</param> /// <returns>tweened value</returns> public static float Ease(EasingMethod method, float t, float b, float c) { switch (method) { case EasingMethod.ExponentialIn: return(ExpoIn(t, b, c)); case EasingMethod.ExponentialOut: return(ExpoOut(t, b, c)); case EasingMethod.ExponentialInOut: return(ExpoInOut(t, b, c)); case EasingMethod.ExponentialOutIn: return(ExpoOutIn(t, b, c)); case EasingMethod.CircularIn: return(CircIn(t, b, c)); case EasingMethod.CircularOut: return(CircOut(t, b, c)); case EasingMethod.CircularInOut: return(CircInOut(t, b, c)); case EasingMethod.CircularOutIn: return(CircOutIn(t, b, c)); case EasingMethod.QuadraticIn: return(QuadIn(t, b, c)); case EasingMethod.QuadraticOut: return(QuadOut(t, b, c)); case EasingMethod.QuadraticInOut: return(QuadInOut(t, b, c)); case EasingMethod.QuadraticOutIn: return(QuadOutIn(t, b, c)); case EasingMethod.SinusIn: return(SineIn(t, b, c)); case EasingMethod.SinusOut: return(SineOut(t, b, c)); case EasingMethod.SinusInOut: return(SineInOut(t, b, c)); case EasingMethod.SinusOutIn: return(SineOutIn(t, b, c)); case EasingMethod.CubicIn: return(CubicIn(t, b, c)); case EasingMethod.CubicOut: return(CubicOut(t, b, c)); case EasingMethod.CubicInOut: return(CubicInOut(t, b, c)); case EasingMethod.CubicOutIn: return(CubicOutIn(t, b, c)); case EasingMethod.QuarticIn: return(QuartIn(t, b, c)); case EasingMethod.QuarticOut: return(QuartOut(t, b, c)); case EasingMethod.QuarticInOut: return(QuartInOut(t, b, c)); case EasingMethod.QuarticOutIn: return(QuartOutIn(t, b, c)); case EasingMethod.QuinticIn: return(QuintIn(t, b, c)); case EasingMethod.QuinticOut: return(QuintOut(t, b, c)); case EasingMethod.QuinticInOut: return(QuintInOut(t, b, c)); case EasingMethod.QuinticOutIn: return(QuintOutIn(t, b, c)); default: return(Linear(t, b, c)); } }
/// <summary> /// Inverts the specified easing method. /// </summary> /// <param name="method">The easing method that should be inverted.</param> /// <returns>An inverted version of the specified easing method.</returns> public static EasingMethod Invert(this EasingMethod method) { return((double progress) => 1 - method(1 - progress)); }
/// <summary>Initializes a new instance of the <seealso cref="EasingInformation"/> struct.</summary> /// <param name="method">The easing method of the easing.</param> /// <param name="easingIn">Determines whether the easing has easing in.</param> /// <param name="easingOut">Determines whether the easing has easing out.</param> public EasingInformation(EasingMethod method, bool easingIn, bool easingOut) { Method = method; EasingIn = easingIn; EasingOut = easingOut; }
/// <summary> /// Reverses the specified easing method. /// </summary> /// <param name="method">The easing method.</param> /// <returns>A reverse version of the specified easing method.</returns> public static EasingMethod Reverse(this EasingMethod method) { return((double progress) => method(1 - progress)); }
/// <summary>Initializes a new instance of the <seealso cref="EasingInformation"/> struct.</summary> /// <param name="easing">The <seealso cref="Easing"/> whose information to retrieve.</param> public EasingInformation(Easing easing) { Method = GetEasingMethod(easing); EasingIn = HasEasingIn(easing); EasingOut = HasEasingOut(easing); }