By D.S.Qiu
尊重他人的劳动,支持原创,转载请注明出处:http://dsqiu.iteye.com
之前有介绍过UITweener(点击前往),NGUI用了一个目录“收集”Tween脚本,集成的功能还是很丰富的,只提供了6种缓动函数(Ease Fuction):Linear,EaseIn,EaseOut,EaseInOut,BounceIn和BounceOut。当时,对缓动函数就只是一知半解。后面为了做文字特效,就发现了 TextFx 插件,这个插件太赞了,让我有种感觉一切效果都可以用代码模拟。TextFx提供了40种缓动函数,表现效果丰富了很多,激动之余,总是想着能不能把这些缓动函数移植到UITweener里面去,所以才有了此文。
下面就直接贴出Ease Function的实现,方便查看。
Method:
扩容之后的Method的样式由6种变为41种:
public enum Method { Linear, EaseIn,EaseOut,EaseInOut,BounceIn,BounceOut, QuadEaseOut, QuadEaseIn, QuadEaseInOut, QuadEaseOutIn, //新增40种动画效果 ExpoEaseOut, ExpoEaseIn, ExpoEaseInOut, ExpoEaseOutIn, CubicEaseOut, CubicEaseIn, CubicEaseInOut, CubicEaseOutIn, QuartEaseOut, QuartEaseIn, QuartEaseInOut, QuartEaseOutIn, QuintEaseOut, QuintEaseIn, QuintEaseInOut, QuintEaseOutIn, CircEaseOut, CircEaseIn, CircEaseInOut, CircEaseOutIn, SineEaseOut, SineEaseIn, SineEaseInOut, SineEaseOutIn, ElasticEaseOut, ElasticEaseIn, ElasticEaseInOut, ElasticEaseOutIn, BounceEaseOut, BounceEaseIn, BounceEaseInOut, BounceEaseOutIn, BackEaseOut, BackEaseIn, BackEaseInOut, BackEaseOutIn }
Sample:
public static float GetEaseProgress(Method ease_type, float linear_progress) { switch (ease_type) { case Method.Linear: return linear_progress; case Method.BackEaseIn: return BackEaseIn(linear_progress, 0, 1, 1); case Method.BackEaseInOut: return BackEaseInOut(linear_progress, 0, 1, 1); case Method.BackEaseOut: return BackEaseOut(linear_progress, 0, 1, 1); case Method.BackEaseOutIn: return BackEaseOutIn(linear_progress, 0, 1, 1); case Method.BounceEaseIn: return BounceEaseIn(linear_progress, 0, 1, 1); case Method.BounceEaseInOut: return BounceEaseInOut(linear_progress, 0, 1, 1); case Method.BounceEaseOut: return BounceEaseOut(linear_progress, 0, 1, 1); case Method.BounceEaseOutIn: return BounceEaseOutIn(linear_progress, 0, 1, 1); case Method.CircEaseIn: return CircEaseIn(linear_progress, 0, 1, 1); case Method.CircEaseInOut: return CircEaseInOut(linear_progress, 0, 1, 1); case Method.CircEaseOut: return CircEaseOut(linear_progress, 0, 1, 1); case Method.CircEaseOutIn: return CircEaseOutIn(linear_progress, 0, 1, 1); case Method.CubicEaseIn: return CubicEaseIn(linear_progress, 0, 1, 1); case Method.CubicEaseInOut: return CubicEaseInOut(linear_progress, 0, 1, 1); case Method.CubicEaseOut: return CubicEaseOut(linear_progress, 0, 1, 1); case Method.CubicEaseOutIn: return CubicEaseOutIn(linear_progress, 0, 1, 1); case Method.ElasticEaseIn: return ElasticEaseIn(linear_progress, 0, 1, 1); case Method.ElasticEaseInOut: return ElasticEaseInOut(linear_progress, 0, 1, 1); case Method.ElasticEaseOut: return ElasticEaseOut(linear_progress, 0, 1, 1); case Method.ElasticEaseOutIn: return ElasticEaseOutIn(linear_progress, 0, 1, 1); case Method.ExpoEaseIn: return ExpoEaseIn(linear_progress, 0, 1, 1); case Method.ExpoEaseInOut: return ExpoEaseInOut(linear_progress, 0, 1, 1); case Method.ExpoEaseOut: return ExpoEaseOut(linear_progress, 0, 1, 1); case Method.ExpoEaseOutIn: return ExpoEaseOutIn(linear_progress, 0, 1, 1); case Method.QuadEaseIn: return QuadEaseIn(linear_progress, 0, 1, 1); case Method.QuadEaseInOut: return QuadEaseInOut(linear_progress, 0, 1, 1); case Method.QuadEaseOut: return QuadEaseOut(linear_progress, 0, 1, 1); case Method.QuadEaseOutIn: return QuadEaseOutIn(linear_progress, 0, 1, 1); case Method.QuartEaseIn: return QuartEaseIn(linear_progress, 0, 1, 1); case Method.QuartEaseInOut: return QuartEaseInOut(linear_progress, 0, 1, 1); case Method.QuartEaseOut: return QuartEaseOut(linear_progress, 0, 1, 1); case Method.QuartEaseOutIn: return QuartEaseOutIn(linear_progress, 0, 1, 1); case Method.QuintEaseIn: return QuintEaseIn(linear_progress, 0, 1, 1); case Method.QuintEaseInOut: return QuintEaseInOut(linear_progress, 0, 1, 1); case Method.QuintEaseOut: return QuintEaseOut(linear_progress, 0, 1, 1); case Method.QuintEaseOutIn: return QuintEaseOutIn(linear_progress, 0, 1, 1); case Method.SineEaseIn: return SineEaseIn(linear_progress, 0, 1, 1); case Method.SineEaseInOut: return SineEaseInOut(linear_progress, 0, 1, 1); case Method.SineEaseOut: return SineEaseOut(linear_progress, 0, 1, 1); case Method.SineEaseOutIn: return SineEaseOutIn(linear_progress, 0, 1, 1); default: return linear_progress; } }
Ease Function:
/* EASING FUNCTIONS */ #region Linear /// <summary> /// Easing equation function for a simple linear tweening, with no easing. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float Linear(float t, float b, float c, float d) { return c * t / d + b; } #endregion #region Expo /// <summary> /// Easing equation function for an exponential (2^t) easing out: /// decelerating from zero velocity. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float ExpoEaseOut(float t, float b, float c, float d) { return (t == d) ? b + c : c * (-Mathf.Pow(2, -10 * t / d) + 1) + b; } /// <summary> /// Easing equation function for an exponential (2^t) easing in: /// accelerating from zero velocity. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float ExpoEaseIn(float t, float b, float c, float d) { return (t == 0) ? b : c * Mathf.Pow(2, 10 * (t / d - 1)) + b; } /// <summary> /// Easing equation function for an exponential (2^t) easing in/out: /// acceleration until halfway, then deceleration. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float ExpoEaseInOut(float t, float b, float c, float d) { if (t == 0) return b; if (t == d) return b + c; if ((t /= d / 2) < 1) return c / 2 * Mathf.Pow(2, 10 * (t - 1)) + b; return c / 2 * (-Mathf.Pow(2, -10 * --t) + 2) + b; } /// <summary> /// Easing equation function for an exponential (2^t) easing out/in: /// deceleration until halfway, then acceleration. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float ExpoEaseOutIn(float t, float b, float c, float d) { if (t < d / 2) return ExpoEaseOut(t * 2, b, c / 2, d); return ExpoEaseIn((t * 2) - d, b + c / 2, c / 2, d); } #endregion #region Circular /// <summary> /// Easing equation function for a circular (sqrt(1-t^2)) easing out: /// decelerating from zero velocity. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float CircEaseOut(float t, float b, float c, float d) { return c * Mathf.Sqrt(1 - (t = t / d - 1) * t) + b; } /// <summary> /// Easing equation function for a circular (sqrt(1-t^2)) easing in: /// accelerating from zero velocity. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float CircEaseIn(float t, float b, float c, float d) { return -c * (Mathf.Sqrt(1 - (t /= d) * t) - 1) + b; } /// <summary> /// Easing equation function for a circular (sqrt(1-t^2)) easing in/out: /// acceleration until halfway, then deceleration. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float CircEaseInOut(float t, float b, float c, float d) { if ((t /= d / 2) < 1) return -c / 2 * (Mathf.Sqrt(1 - t * t) - 1) + b; return c / 2 * (Mathf.Sqrt(1 - (t -= 2) * t) + 1) + b; } /// <summary> /// Easing equation function for a circular (sqrt(1-t^2)) easing in/out: /// acceleration until halfway, then deceleration. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float CircEaseOutIn(float t, float b, float c, float d) { if (t < d / 2) return CircEaseOut(t * 2, b, c / 2, d); return CircEaseIn((t * 2) - d, b + c / 2, c / 2, d); } #endregion #region Quad /// <summary> /// Easing equation function for a quadratic (t^2) easing out: /// decelerating from zero velocity. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float QuadEaseOut(float t, float b, float c, float d) { return -c * (t /= d) * (t - 2) + b; } /// <summary> /// Easing equation function for a quadratic (t^2) easing in: /// accelerating from zero velocity. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float QuadEaseIn(float t, float b, float c, float d) { return c * (t /= d) * t + b; } /// <summary> /// Easing equation function for a quadratic (t^2) easing in/out: /// acceleration until halfway, then deceleration. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float QuadEaseInOut(float t, float b, float c, float d) { if ((t /= d / 2) < 1) return c / 2 * t * t + b; return -c / 2 * ((--t) * (t - 2) - 1) + b; } /// <summary> /// Easing equation function for a quadratic (t^2) easing out/in: /// deceleration until halfway, then acceleration. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float QuadEaseOutIn(float t, float b, float c, float d) { if (t < d / 2) return QuadEaseOut(t * 2, b, c / 2, d); return QuadEaseIn((t * 2) - d, b + c / 2, c / 2, d); } #endregion #region Sine /// <summary> /// Easing equation function for a sinusoidal (sin(t)) easing out: /// decelerating from zero velocity. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float SineEaseOut(float t, float b, float c, float d) { return c * Mathf.Sin(t / d * (Mathf.PI / 2)) + b; } /// <summary> /// Easing equation function for a sinusoidal (sin(t)) easing in: /// accelerating from zero velocity. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float SineEaseIn(float t, float b, float c, float d) { return -c * Mathf.Cos(t / d * (Mathf.PI / 2)) + c + b; } /// <summary> /// Easing equation function for a sinusoidal (sin(t)) easing in/out: /// acceleration until halfway, then deceleration. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float SineEaseInOut(float t, float b, float c, float d) { if ((t /= d / 2) < 1) return c / 2 * (Mathf.Sin(Mathf.PI * t / 2)) + b; return -c / 2 * (Mathf.Cos(Mathf.PI * --t / 2) - 2) + b; } /// <summary> /// Easing equation function for a sinusoidal (sin(t)) easing in/out: /// deceleration until halfway, then acceleration. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float SineEaseOutIn(float t, float b, float c, float d) { if (t < d / 2) return SineEaseOut(t * 2, b, c / 2, d); return SineEaseIn((t * 2) - d, b + c / 2, c / 2, d); } #endregion #region Cubic /// <summary> /// Easing equation function for a cubic (t^3) easing out: /// decelerating from zero velocity. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float CubicEaseOut(float t, float b, float c, float d) { return c * ((t = t / d - 1) * t * t + 1) + b; } /// <summary> /// Easing equation function for a cubic (t^3) easing in: /// accelerating from zero velocity. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float CubicEaseIn(float t, float b, float c, float d) { return c * (t /= d) * t * t + b; } /// <summary> /// Easing equation function for a cubic (t^3) easing in/out: /// acceleration until halfway, then deceleration. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float CubicEaseInOut(float t, float b, float c, float d) { if ((t /= d / 2) < 1) return c / 2 * t * t * t + b; return c / 2 * ((t -= 2) * t * t + 2) + b; } /// <summary> /// Easing equation function for a cubic (t^3) easing out/in: /// deceleration until halfway, then acceleration. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float CubicEaseOutIn(float t, float b, float c, float d) { if (t < d / 2) return CubicEaseOut(t * 2, b, c / 2, d); return CubicEaseIn((t * 2) - d, b + c / 2, c / 2, d); } #endregion #region Quartic /// <summary> /// Easing equation function for a quartic (t^4) easing out: /// decelerating from zero velocity. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float QuartEaseOut(float t, float b, float c, float d) { return -c * ((t = t / d - 1) * t * t * t - 1) + b; } /// <summary> /// Easing equation function for a quartic (t^4) easing in: /// accelerating from zero velocity. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float QuartEaseIn(float t, float b, float c, float d) { return c * (t /= d) * t * t * t + b; } /// <summary> /// Easing equation function for a quartic (t^4) easing in/out: /// acceleration until halfway, then deceleration. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float QuartEaseInOut(float t, float b, float c, float d) { if ((t /= d / 2) < 1) return c / 2 * t * t * t * t + b; return -c / 2 * ((t -= 2) * t * t * t - 2) + b; } /// <summary> /// Easing equation function for a quartic (t^4) easing out/in: /// deceleration until halfway, then acceleration. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float QuartEaseOutIn(float t, float b, float c, float d) { if (t < d / 2) return QuartEaseOut(t * 2, b, c / 2, d); return QuartEaseIn((t * 2) - d, b + c / 2, c / 2, d); } #endregion #region Quintic /// <summary> /// Easing equation function for a quintic (t^5) easing out: /// decelerating from zero velocity. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float QuintEaseOut(float t, float b, float c, float d) { return c * ((t = t / d - 1) * t * t * t * t + 1) + b; } /// <summary> /// Easing equation function for a quintic (t^5) easing in: /// accelerating from zero velocity. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float QuintEaseIn(float t, float b, float c, float d) { return c * (t /= d) * t * t * t * t + b; } /// <summary> /// Easing equation function for a quintic (t^5) easing in/out: /// acceleration until halfway, then deceleration. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float QuintEaseInOut(float t, float b, float c, float d) { if ((t /= d / 2) < 1) return c / 2 * t * t * t * t * t + b; return c / 2 * ((t -= 2) * t * t * t * t + 2) + b; } /// <summary> /// Easing equation function for a quintic (t^5) easing in/out: /// acceleration until halfway, then deceleration. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float QuintEaseOutIn(float t, float b, float c, float d) { if (t < d / 2) return QuintEaseOut(t * 2, b, c / 2, d); return QuintEaseIn((t * 2) - d, b + c / 2, c / 2, d); } #endregion #region Elastic /// <summary> /// Easing equation function for an elastic (exponentially decaying sine wave) easing out: /// decelerating from zero velocity. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float ElasticEaseOut(float t, float b, float c, float d) { if ((t /= d) == 1) return b + c; float p = d * 0.3f; float s = p / 4; return (c * Mathf.Pow(2, -10 * t) * Mathf.Sin((t * d - s) * (2 * Mathf.PI) / p) + c + b); } /// <summary> /// Easing equation function for an elastic (exponentially decaying sine wave) easing in: /// accelerating from zero velocity. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float ElasticEaseIn(float t, float b, float c, float d) { if ((t /= d) == 1) return b + c; float p = d * 0.3f; float s = p / 4; return -(c * Mathf.Pow(2, 10 * (t -= 1)) * Mathf.Sin((t * d - s) * (2 * Mathf.PI) / p)) + b; } /// <summary> /// Easing equation function for an elastic (exponentially decaying sine wave) easing in/out: /// acceleration until halfway, then deceleration. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float ElasticEaseInOut(float t, float b, float c, float d) { if ((t /= d / 2f) == 2) return b + c; float p = d * (0.3f * 1.5f); float s = p / 4; if (t < 1) return -0.5f * (c * Mathf.Pow(2, 10 * (t -= 1)) * Mathf.Sin((t * d - s) * (2 * Mathf.PI) / p)) + b; return c * Mathf.Pow(2, -10 * (t -= 1)) * Mathf.Sin((t * d - s) * (2 * Mathf.PI) / p) * 0.5f + c + b; } /// <summary> /// Easing equation function for an elastic (exponentially decaying sine wave) easing out/in: /// deceleration until halfway, then acceleration. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float ElasticEaseOutIn(float t, float b, float c, float d) { if (t < d / 2) return ElasticEaseOut(t * 2, b, c / 2, d); return ElasticEaseIn((t * 2) - d, b + c / 2, c / 2, d); } #endregion #region Bounce /// <summary> /// Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out: /// decelerating from zero velocity. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float BounceEaseOut(float t, float b, float c, float d) { if ((t /= d) < (1 / 2.75f)) return c * (7.5625f * t * t) + b; else if (t < (2 / 2.75f)) return c * (7.5625f * (t -= (1.5f / 2.75f)) * t + 0.75f) + b; else if (t < (2.5f / 2.75f)) return c * (7.5625f * (t -= (2.25f / 2.75f)) * t + 0.9375f) + b; else return c * (7.5625f * (t -= (2.625f / 2.75f)) * t + .984375f) + b; } /// <summary> /// Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in: /// accelerating from zero velocity. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float BounceEaseIn(float t, float b, float c, float d) { return c - BounceEaseOut(d - t, 0, c, d) + b; } /// <summary> /// Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in/out: /// acceleration until halfway, then deceleration. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float BounceEaseInOut(float t, float b, float c, float d) { if (t < d / 2) return BounceEaseIn(t * 2, 0, c, d) * 0.5f + b; else return BounceEaseOut(t * 2 - d, 0, c, d) * 0.5f + c * 0.5f + b; } /// <summary> /// Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out/in: /// deceleration until halfway, then acceleration. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float BounceEaseOutIn(float t, float b, float c, float d) { if (t < d / 2) return BounceEaseOut(t * 2, b, c / 2, d); return BounceEaseIn((t * 2) - d, b + c / 2, c / 2, d); } #endregion #region Back /// <summary> /// Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out: /// decelerating from zero velocity. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float BackEaseOut(float t, float b, float c, float d) { return c * ((t = t / d - 1) * t * ((1.70158f + 1) * t + 1.70158f) + 1) + b; } /// <summary> /// Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in: /// accelerating from zero velocity. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float BackEaseIn(float t, float b, float c, float d) { return c * (t /= d) * t * ((1.70158f + 1) * t - 1.70158f) + b; } /// <summary> /// Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in/out: /// acceleration until halfway, then deceleration. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float BackEaseInOut(float t, float b, float c, float d) { float s = 1.70158f; if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= (1.525f)) + 1) * t - s)) + b; return c / 2 * ((t -= 2) * t * (((s *= (1.525f)) + 1) * t + s) + 2) + b; } /// <summary> /// Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out/in: /// deceleration until halfway, then acceleration. /// </summary> /// <param name="t">Current time in seconds.</param> /// <param name="b">Starting value.</param> /// <param name="c">Final value.</param> /// <param name="d">Duration of animation.</param> /// <returns>The correct value.</returns> public static float BackEaseOutIn(float t, float b, float c, float d) { if (t < d / 2) return BackEaseOut(t * 2, b, c / 2, d); return BackEaseIn((t * 2) - d, b + c / 2, c / 2, d); } #endregion
小结:
首先,非常感谢TextFx的作者,然后 TextFx 的插件真的很棒,实用又简单,而不会华而不实。在UITweener的文章中也对缓动函数有介绍,贴出其中30种的轨迹图,会更加直观。此文是为了大家能够检索到需要的内容。
『
在UITweener的文末附上了30中缓动曲线的图形,感觉有点不够动态,参考①中给出的效果会更好些,更容易理解和体会。』
增补于 2014,1,14 9:25
如果您对D.S.Qiu有任何建议或意见可以在文章后面评论,或者发邮件(gd.s.qiu@gmail.com)交流,您的鼓励和支持是我前进的动力,希望能有更多更好的分享。
转载请在文首注明出处:http://dsqiu.iteye.com/blog/2001007
更多精彩请关注D.S.Qiu的博客和微博(ID:静水逐风)
参考:
①robertpenner.com: http://www.robertpenner.com/easing/easing_demo.html
相关推荐
TextFx-Unity文字效果插件。 马上注册,加入CGJOY,让你轻松玩转CGJOY。 您需要 登录 才可以下载或查看,没有帐号?立即注册 x TextFX 2.0 unity3d文字特效工具 TextFX是一个功能强大的文本网状动画...
unity 的文字动画插件TextFx3.3.0最新版,炫酷的文字动画,多种动画实现。随意需改文字。Unity文字特效插件TextFX v3.3.0 支持unity2020.
Unity TextFx是一款在Unity引擎中用于创建文字动画和特效的扩展工具。它为开发者提供了丰富的预设效果,如文字漂浮、闪烁、旋转等,帮助游戏设计师和开发者快速实现动态和吸引人的文字视觉表现,从而增强游戏或应用...
TextFX v3.2.1.unitypackage 文字的一些动画. 省得自己调节
Notepad++ TextFX是一个经典的Notepad++插件,拥有代码转换、插入、优化、格式化、验证等功能,以前的Notepad++版本集成了TextFX插件,但是在新版本中就去掉了,用户如果需要TextFX插件,只能手动安装了
unity著名的文字特效制作工具TextFX的2.81版本,内附几十种文字特效模板,是制作精美文字特效动画必不可少的工具,这款插件资源商店要卖30刀哟~
TextFx v2.0 快速方便制作Unity文本特效的unitypackage:)
TextFx主要包括TextFx Quick、TextFx Edit和TextFx Characters等模块,它们能够帮助用户快速执行诸如转换大小写、删除空白行、排序行、查找和替换文本等一系列复杂的文本操作。例如,TextFx Quick可以方便地实现...
酷炫的Unity文字特效,可以使用Bitmap工具制作中文字体,可以自定义动画。
《Notepad++插件TextFX详解与应用》 在编程和文本编辑的世界中,Notepad++是一款备受青睐的免费源代码编辑器,尤其对于Windows用户来说。它支持多种编程语言,并且具有轻量级、可扩展性强的特点。而TextFX则是...
在本主题中,我们关注的是一个特定的插件——"Unity卡通特效字母文字TextFx插件"。这个插件为Unity开发者提供了丰富多样的文字和字母特效,为游戏增添更多视觉吸引力,提升用户体验。 "TextFx"插件专为在Unity中...
Unity文字特效插件TextFX v3.2.9
npp++ 32位,从官网下载的,因为处理文本需要,TextFx插件,但是这个插件只支持32位的。 该压缩包包含: npp++ 32位 PluginManager TextFX.v0.26.unicode.bin
textfx 是一个方便的 jquery 插件,用于提供很棒的文本效果! TextFX 现在可以通过 bower 使用了! bower install chriscates-textfx 包括这些文件: [removed][removed] [removed][removed] [removed][removed] ...
2. **动画工具**:提供自定义动画预设,如“Easy Ease”或“wiggle expressions”可快速创建平滑的缓动或随机动画。 3. **特效生成器**:脚本可以生成复杂的粒子系统、文字动画、光效等特效,如“Particular ...
在IT行业中,场景和特效是数字内容创作的重要组成部分,尤其在游戏开发、影视制作、虚拟现实(VR)和增强现实(AR)等领域中扮演着关键角色。本压缩包集合了15个高质量的场景和特效资源,每个资源都有较高的实用性和...
4. **专门的转换工具**:市面上也有一些专门用于文件编码转换的软件,比如TextFX(Notepad++的一个插件)或ENCODER工具等。 在处理非UTF-8编码的文本文件时,需要注意一些潜在问题,如乱码、丢失字符或无法识别的...
《NotePad++插件——TextFx的深度解析》 NotePad++是一款广受开发者喜爱的免费源代码编辑器,尤其以其轻量级、高效和强大的语法高亮功能著称。而今天我们要探讨的是NotePad++的一个重要插件——TextFx,它极大地...
《Notepad++文本处理插件TextFX详解》 Notepad++是一款广受欢迎的免费源代码编辑器,尤其在程序员和Web开发者中具有很高的使用率。它支持多种编程语言,并且可扩展性强,允许用户安装各种插件以增强功能。TextFX...