From 9732b490aadad78fe84a54c87009e313e568d2b6 Mon Sep 17 00:00:00 2001 From: Demigiant Date: Sat, 31 Oct 2015 15:42:40 +0100 Subject: [PATCH] Adding period to Flash eases --- .../DOTween/Core/Easing/EaseManager.cs | 81 +++++++++++++------ _DOTween.Assembly/DOTween/DOTween.cs | 2 +- 2 files changed, 59 insertions(+), 24 deletions(-) diff --git a/_DOTween.Assembly/DOTween/Core/Easing/EaseManager.cs b/_DOTween.Assembly/DOTween/Core/Easing/EaseManager.cs index 2a489e2..6ddb7bf 100644 --- a/_DOTween.Assembly/DOTween/Core/Easing/EaseManager.cs +++ b/_DOTween.Assembly/DOTween/Core/Easing/EaseManager.cs @@ -61,7 +61,8 @@ namespace DG.Tweening.Core.Easing /// public static float Evaluate(Ease easeType, EaseFunction customEase, float time, float duration, float overshootOrAmplitude, float period) { - float durationStep; + int stepIndex; + float stepDuration; int dir; switch (easeType) { @@ -170,44 +171,78 @@ namespace DG.Tweening.Core.Easing // Extra custom eases //////////////////////////////////////////////////// case Ease.Flash: - durationStep = duration / overshootOrAmplitude; - dir = 1; - while (time > durationStep) { - time -= durationStep; - dir = -dir; +// stepIndex = Mathf.CeilToInt((time / duration) * overshootOrAmplitude); // 1 to overshootOrAmplitude +// stepDuration = duration / overshootOrAmplitude; +// time -= stepDuration * (stepIndex - 1); +// dir = (stepIndex % 2 != 0) ? 1 : - 1; +// if (dir < 0) time -= stepDuration; +// float res = (time * dir) / stepDuration; +// if (period > 0) { +// float easedRes = (res * (overshootOrAmplitude - stepIndex)) / overshootOrAmplitude; +// float diff = easedRes - res; +// diff = diff * period; +// return res + diff; +// } +// if (period < 0) { +// period = -period; +// float easedRes = (res * stepIndex) / overshootOrAmplitude; +// float diff = easedRes - res; +// diff = diff * period; +// return res + diff; +// } +// return res; + + float final = 0; + stepIndex = Mathf.CeilToInt((time / duration) * overshootOrAmplitude); // 1 to overshootOrAmplitude + stepDuration = duration / overshootOrAmplitude; + time -= stepDuration * (stepIndex - 1); + dir = (stepIndex % 2 != 0) ? 1 : - 1; + if (dir < 0) time -= stepDuration; + float res = (time * dir) / stepDuration; + float easedRes = 0; + if (period > 0) { + final = overshootOrAmplitude - (float)Math.Truncate(overshootOrAmplitude); + if ((float)Math.Truncate(overshootOrAmplitude) % 2 > 0) final = 1 - final; + final = (final * stepIndex) / overshootOrAmplitude; + easedRes = (res * (overshootOrAmplitude - stepIndex)) / overshootOrAmplitude; + } else if (period < 0) { + period = -period; + easedRes = (res * stepIndex) / overshootOrAmplitude; } - if (dir < 0) time -= durationStep; - return (time * dir) / durationStep; + float diff = easedRes - res; + res += (diff * period) + final; + if (res > 1) res = 1; + return res; case Ease.InFlash: - durationStep = duration / overshootOrAmplitude; + stepDuration = duration / overshootOrAmplitude; dir = 1; - while (time > durationStep) { - time -= durationStep; + while (time > stepDuration) { + time -= stepDuration; dir = -dir; } - if (dir < 0) time -= durationStep; + if (dir < 0) time -= stepDuration; time = time * dir; - return (time /= durationStep) * time; + return (time /= stepDuration) * time; case Ease.OutFlash: - durationStep = duration / overshootOrAmplitude; + stepDuration = duration / overshootOrAmplitude; dir = 1; - while (time > durationStep) { - time -= durationStep; + while (time > stepDuration) { + time -= stepDuration; dir = -dir; } - if (dir < 0) time -= durationStep; + if (dir < 0) time -= stepDuration; time = time * dir; - return -(time /= durationStep) * (time - 2); + return -(time /= stepDuration) * (time - 2); case Ease.InOutFlash: - durationStep = duration / overshootOrAmplitude; + stepDuration = duration / overshootOrAmplitude; dir = 1; - while (time > durationStep) { - time -= durationStep; + while (time > stepDuration) { + time -= stepDuration; dir = -dir; } - if (dir < 0) time -= durationStep; + if (dir < 0) time -= stepDuration; time = time * dir; - if ((time /= durationStep * 0.5f) < 1) return 0.5f * time * time; + if ((time /= stepDuration * 0.5f) < 1) return 0.5f * time * time; return -0.5f * ((--time) * (time - 2) - 1); // Default diff --git a/_DOTween.Assembly/DOTween/DOTween.cs b/_DOTween.Assembly/DOTween/DOTween.cs index afb75fc..0fa039f 100644 --- a/_DOTween.Assembly/DOTween/DOTween.cs +++ b/_DOTween.Assembly/DOTween/DOTween.cs @@ -32,7 +32,7 @@ namespace DG.Tweening public class DOTween { /// DOTween's version - public static readonly string Version = "1.1.050"; + public static readonly string Version = "1.1.060"; /////////////////////////////////////////////// // Options ////////////////////////////////////