1
0
mirror of https://github.com/Cardidi/dotween-upm-fork.git synced 2025-12-20 17:26:03 +08:00

Period successfully added to Flash eases

This commit is contained in:
Demigiant 2015-10-31 16:37:11 +01:00
parent 9732b490aa
commit 2af024f03d
53 changed files with 156 additions and 148 deletions

View File

@ -2040,16 +2040,22 @@
<summary>Sets the ease of the tween.
<para>If applied to Sequences eases the whole sequence animation</para></summary>
<param name="overshoot">
Eventual overshoot to use with Back ease (default is 1.70158).
Eventual overshoot to use with Back or Flash ease (default is 1.70158).
<para>In case of Flash ease it sets the total number of flashes that will happen.
Using an even number will end the tween on the starting value, while an odd one will end on the end value.</para>
Using an even number will complete the tween on the starting value, while an odd one will complete it on the end value.</para>
</param>
</member>
<member name="M:DG.Tweening.TweenSettingsExtensions.SetEase``1(``0,DG.Tweening.Ease,System.Single,System.Single)">
<summary>Sets the ease of the tween.
<para>If applied to Sequences eases the whole sequence animation</para></summary>
<param name="amplitude">Eventual amplitude to use with Elastic easeType (default is 1.70158)</param>
<param name="period">Eventual period to use with Elastic easeType (default is 0)</param>
<param name="amplitude">Eventual amplitude to use with Elastic easeType or overshoot to use with Flash easeType (default is 1.70158).
<para>In case of Flash ease it sets the total number of flashes that will happen.
Using an even number will complete the tween on the starting value, while an odd one will complete it on the end value.</para>
</param>
<param name="period">Eventual period to use with Elastic or Flash easeType (default is 0).
<para>In case of Flash ease it indicates the power in time of the ease, and must be between -1 and 1.
0 is balanced, 1 weakens the ease with time, -1 starts the ease weakened and gives it power towards the end.</para>
</param>
</member>
<member name="M:DG.Tweening.TweenSettingsExtensions.SetEase``1(``0,UnityEngine.AnimationCurve)">
<summary>Sets the ease of the tween using an AnimationCurve.

View File

@ -2040,16 +2040,22 @@
<summary>Sets the ease of the tween.
<para>If applied to Sequences eases the whole sequence animation</para></summary>
<param name="overshoot">
Eventual overshoot to use with Back ease (default is 1.70158).
Eventual overshoot to use with Back or Flash ease (default is 1.70158).
<para>In case of Flash ease it sets the total number of flashes that will happen.
Using an even number will end the tween on the starting value, while an odd one will end on the end value.</para>
Using an even number will complete the tween on the starting value, while an odd one will complete it on the end value.</para>
</param>
</member>
<member name="M:DG.Tweening.TweenSettingsExtensions.SetEase``1(``0,DG.Tweening.Ease,System.Single,System.Single)">
<summary>Sets the ease of the tween.
<para>If applied to Sequences eases the whole sequence animation</para></summary>
<param name="amplitude">Eventual amplitude to use with Elastic easeType (default is 1.70158)</param>
<param name="period">Eventual period to use with Elastic easeType (default is 0)</param>
<param name="amplitude">Eventual amplitude to use with Elastic easeType or overshoot to use with Flash easeType (default is 1.70158).
<para>In case of Flash ease it sets the total number of flashes that will happen.
Using an even number will complete the tween on the starting value, while an odd one will complete it on the end value.</para>
</param>
<param name="period">Eventual period to use with Elastic or Flash easeType (default is 0).
<para>In case of Flash ease it indicates the power in time of the ease, and must be between -1 and 1.
0 is balanced, 1 weakens the ease with time, -1 starts the ease weakened and gives it power towards the end.</para>
</param>
</member>
<member name="M:DG.Tweening.TweenSettingsExtensions.SetEase``1(``0,UnityEngine.AnimationCurve)">
<summary>Sets the ease of the tween using an AnimationCurve.

View File

@ -2040,16 +2040,22 @@
<summary>Sets the ease of the tween.
<para>If applied to Sequences eases the whole sequence animation</para></summary>
<param name="overshoot">
Eventual overshoot to use with Back ease (default is 1.70158).
Eventual overshoot to use with Back or Flash ease (default is 1.70158).
<para>In case of Flash ease it sets the total number of flashes that will happen.
Using an even number will end the tween on the starting value, while an odd one will end on the end value.</para>
Using an even number will complete the tween on the starting value, while an odd one will complete it on the end value.</para>
</param>
</member>
<member name="M:DG.Tweening.TweenSettingsExtensions.SetEase``1(``0,DG.Tweening.Ease,System.Single,System.Single)">
<summary>Sets the ease of the tween.
<para>If applied to Sequences eases the whole sequence animation</para></summary>
<param name="amplitude">Eventual amplitude to use with Elastic easeType (default is 1.70158)</param>
<param name="period">Eventual period to use with Elastic easeType (default is 0)</param>
<param name="amplitude">Eventual amplitude to use with Elastic easeType or overshoot to use with Flash easeType (default is 1.70158).
<para>In case of Flash ease it sets the total number of flashes that will happen.
Using an even number will complete the tween on the starting value, while an odd one will complete it on the end value.</para>
</param>
<param name="period">Eventual period to use with Elastic or Flash easeType (default is 0).
<para>In case of Flash ease it indicates the power in time of the ease, and must be between -1 and 1.
0 is balanced, 1 weakens the ease with time, -1 starts the ease weakened and gives it power towards the end.</para>
</param>
</member>
<member name="M:DG.Tweening.TweenSettingsExtensions.SetEase``1(``0,UnityEngine.AnimationCurve)">
<summary>Sets the ease of the tween using an AnimationCurve.

View File

@ -10,6 +10,8 @@ public class EaseCurves : BrainBase
public AnimationCurve easeCurve;
public float tweenDuration = 1;
public int txDistance = 2;
public float easeFlashOvershoot = 16;
public float easeFlashPeriod = 1;
int txH, txW;
int txBorder, easeH;
@ -75,10 +77,10 @@ public class EaseCurves : BrainBase
img.GetComponentInChildren<Text>().text = easeType.ToString();
if (easeType == Ease.INTERNAL_Custom) tween.SetEase(easeCurve);
else{
float overshootOrAmplitude = easeType.ToString().IndexOf("Flash") == -1
? DOTween.defaultEaseOvershootOrAmplitude
: 16;
tween.SetEase(easeType, overshootOrAmplitude);
bool isFlashEase = easeType.ToString().IndexOf("Flash") != -1;
float overshootOrAmplitude = isFlashEase ? easeFlashOvershoot : DOTween.defaultEaseOvershootOrAmplitude;
float period = isFlashEase ? easeFlashPeriod : DOTween.defaultEasePeriod;
tween.SetEase(easeType, overshootOrAmplitude, period);
}
}
}

View File

@ -10,14 +10,15 @@ public class EaseX : MonoBehaviour
[Header("Tween Settings")]
public float duration = 2;
public Ease ease;
public float overshootOrAmplitude = 10;
public float overshootOrAmplitude = 16;
public float period = 1;
public void Play()
{
DOTween.RewindAll();
DOTween.KillAll();
imgFlash.DOColor(flashColor, duration).SetEase(ease, overshootOrAmplitude);
imgSmoothFlash.DOColor(flashColor, duration).SetEase(ease, overshootOrAmplitude);
imgFlash.DOColor(flashColor, duration).SetEase(ease, overshootOrAmplitude, period);
imgSmoothFlash.DOColor(flashColor, duration).SetEase(ease, overshootOrAmplitude - 1, period);
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.5 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -61,10 +61,6 @@ namespace DG.Tweening.Core.Easing
/// </summary>
public static float Evaluate(Ease easeType, EaseFunction customEase, float time, float duration, float overshootOrAmplitude, float period)
{
int stepIndex;
float stepDuration;
int dir;
switch (easeType) {
case Ease.Linear:
return time / duration;
@ -171,79 +167,13 @@ namespace DG.Tweening.Core.Easing
// Extra custom eases ////////////////////////////////////////////////////
case Ease.Flash:
// 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;
}
float diff = easedRes - res;
res += (diff * period) + final;
if (res > 1) res = 1;
return res;
return Flash.Ease(time, duration, overshootOrAmplitude, period);
case Ease.InFlash:
stepDuration = duration / overshootOrAmplitude;
dir = 1;
while (time > stepDuration) {
time -= stepDuration;
dir = -dir;
}
if (dir < 0) time -= stepDuration;
time = time * dir;
return (time /= stepDuration) * time;
return Flash.EaseIn(time, duration, overshootOrAmplitude, period);
case Ease.OutFlash:
stepDuration = duration / overshootOrAmplitude;
dir = 1;
while (time > stepDuration) {
time -= stepDuration;
dir = -dir;
}
if (dir < 0) time -= stepDuration;
time = time * dir;
return -(time /= stepDuration) * (time - 2);
return Flash.EaseOut(time, duration, overshootOrAmplitude, period);
case Ease.InOutFlash:
stepDuration = duration / overshootOrAmplitude;
dir = 1;
while (time > stepDuration) {
time -= stepDuration;
dir = -dir;
}
if (dir < 0) time -= stepDuration;
time = time * dir;
if ((time /= stepDuration * 0.5f) < 1) return 0.5f * time * time;
return -0.5f * ((--time) * (time - 2) - 1);
return Flash.EaseInOut(time, duration, overshootOrAmplitude, period);
// Default
default:
@ -254,9 +184,6 @@ namespace DG.Tweening.Core.Easing
public static EaseFunction ToEaseFunction(Ease ease)
{
float durationStep;
int dir;
switch (ease) {
case Ease.Linear:
return (float time, float duration, float overshootOrAmplitude, float period) =>
@ -400,53 +327,17 @@ namespace DG.Tweening.Core.Easing
// Extra custom eases ////////////////////////////////////////////////////
case Ease.Flash:
return (float time, float duration, float overshootOrAmplitude, float period) => {
durationStep = duration / overshootOrAmplitude;
dir = 1;
while (time > durationStep) {
time -= durationStep;
dir = -dir;
}
if (dir < 0) time -= durationStep;
return (time * dir) / durationStep;
};
return (float time, float duration, float overshootOrAmplitude, float period) =>
Flash.Ease(time, duration, overshootOrAmplitude, period);
case Ease.InFlash:
return (float time, float duration, float overshootOrAmplitude, float period) => {
durationStep = duration / overshootOrAmplitude;
dir = 1;
while (time > durationStep) {
time -= durationStep;
dir = -dir;
}
if (dir < 0) time -= durationStep;
time = time * dir;
return (time /= durationStep) * time;
};
return (float time, float duration, float overshootOrAmplitude, float period) =>
Flash.EaseIn(time, duration, overshootOrAmplitude, period);
case Ease.OutFlash:
return (float time, float duration, float overshootOrAmplitude, float period) => {
durationStep = duration / overshootOrAmplitude;
dir = 1;
while (time > durationStep) {
time -= durationStep;
dir = -dir;
}
if (dir < 0) time -= durationStep;
time = time * dir;
return -(time /= durationStep) * (time - 2);
};
return (float time, float duration, float overshootOrAmplitude, float period) =>
Flash.EaseOut(time, duration, overshootOrAmplitude, period);
case Ease.InOutFlash:
return (float time, float duration, float overshootOrAmplitude, float period) => {
durationStep = duration / overshootOrAmplitude;
dir = 1;
while (time > durationStep) {
time -= durationStep;
dir = -dir;
}
if (dir < 0) time -= durationStep;
time = time * dir;
if ((time /= durationStep * 0.5f) < 1) return 0.5f * time * time;
return -0.5f * ((--time) * (time - 2) - 1);
};
return (float time, float duration, float overshootOrAmplitude, float period) =>
Flash.EaseInOut(time, duration, overshootOrAmplitude, period);
// Default
default:

View File

@ -0,0 +1,83 @@
// Author: Daniele Giardini - http://www.demigiant.com
// Created: 2015/10/31 15:59
// License Copyright (c) Daniele Giardini
// This work is subject to the terms at http://dotween.demigiant.com/license.php
using System;
using UnityEngine;
#pragma warning disable 1591
namespace DG.Tweening.Core.Easing
{
public static class Flash
{
public static float Ease(float time, float duration, float overshootOrAmplitude, float period)
{
int stepIndex = Mathf.CeilToInt((time / duration) * overshootOrAmplitude); // 1 to overshootOrAmplitude
float stepDuration = duration / overshootOrAmplitude;
time -= stepDuration * (stepIndex - 1);
float dir = (stepIndex % 2 != 0) ? 1 : -1;
if (dir < 0) time -= stepDuration;
float res = (time * dir) / stepDuration;
return WeightedEase(overshootOrAmplitude, period, stepIndex, stepDuration, dir, res);
}
public static float EaseIn(float time, float duration, float overshootOrAmplitude, float period)
{
int stepIndex = Mathf.CeilToInt((time / duration) * overshootOrAmplitude); // 1 to overshootOrAmplitude
float stepDuration = duration / overshootOrAmplitude;
time -= stepDuration * (stepIndex - 1);
float dir = (stepIndex % 2 != 0) ? 1 : -1;
if (dir < 0) time -= stepDuration;
time = time * dir;
float res = (time /= stepDuration) * time;
return WeightedEase(overshootOrAmplitude, period, stepIndex, stepDuration, dir, res);
}
public static float EaseOut(float time, float duration, float overshootOrAmplitude, float period)
{
int stepIndex = Mathf.CeilToInt((time / duration) * overshootOrAmplitude); // 1 to overshootOrAmplitude
float stepDuration = duration / overshootOrAmplitude;
time -= stepDuration * (stepIndex - 1);
float dir = (stepIndex % 2 != 0) ? 1 : -1;
if (dir < 0) time -= stepDuration;
time = time * dir;
float res = -(time /= stepDuration) * (time - 2);
return WeightedEase(overshootOrAmplitude, period, stepIndex, stepDuration, dir, res);
}
public static float EaseInOut(float time, float duration, float overshootOrAmplitude, float period)
{
int stepIndex = Mathf.CeilToInt((time / duration) * overshootOrAmplitude); // 1 to overshootOrAmplitude
float stepDuration = duration / overshootOrAmplitude;
time -= stepDuration * (stepIndex - 1);
float dir = (stepIndex % 2 != 0) ? 1 : -1;
if (dir < 0) time -= stepDuration;
time = time * dir;
float res = (time /= stepDuration * 0.5f) < 1
? 0.5f * time * time
: -0.5f * ((--time) * (time - 2) - 1);
return WeightedEase(overshootOrAmplitude, period, stepIndex, stepDuration, dir, res);
}
static float WeightedEase(float overshootOrAmplitude, float period, int stepIndex, float stepDuration, float dir, float res)
{
float easedRes = 0;
float finalDecimals = 0;
if (period > 0) {
float finalTruncated = (float)Math.Truncate(overshootOrAmplitude);
finalDecimals = overshootOrAmplitude - finalTruncated;
if (finalTruncated % 2 > 0) finalDecimals = 1 - finalDecimals;
finalDecimals = (finalDecimals * stepIndex) / overshootOrAmplitude;
easedRes = (res * (overshootOrAmplitude - stepIndex)) / overshootOrAmplitude;
} else if (period < 0) {
period = -period;
easedRes = (res * stepIndex) / overshootOrAmplitude;
}
float diff = easedRes - res;
res += (diff * period) + finalDecimals;
if (res > 1) res = 1;
return res;
}
}
}

View File

@ -65,6 +65,7 @@
<Compile Include="Core\Easing\Bounce.cs" />
<Compile Include="Core\Easing\EaseManager.cs" />
<Compile Include="Core\Easing\EaseCurve.cs" />
<Compile Include="Core\Easing\Flash.cs" />
<Compile Include="Core\Enums\FilterType.cs" />
<Compile Include="Core\Enums\OperationType.cs" />
<Compile Include="Core\Enums\SpecialStartupMode.cs" />

View File

@ -127,9 +127,9 @@ namespace DG.Tweening
/// <summary>Sets the ease of the tween.
/// <para>If applied to Sequences eases the whole sequence animation</para></summary>
/// <param name="overshoot">
/// Eventual overshoot to use with Back ease (default is 1.70158).
/// Eventual overshoot to use with Back or Flash ease (default is 1.70158).
/// <para>In case of Flash ease it sets the total number of flashes that will happen.
/// Using an even number will end the tween on the starting value, while an odd one will end on the end value.</para>
/// Using an even number will complete the tween on the starting value, while an odd one will complete it on the end value.</para>
/// </param>
public static T SetEase<T>(this T t, Ease ease, float overshoot) where T : Tween
{
@ -142,8 +142,14 @@ namespace DG.Tweening
}
/// <summary>Sets the ease of the tween.
/// <para>If applied to Sequences eases the whole sequence animation</para></summary>
/// <param name="amplitude">Eventual amplitude to use with Elastic easeType (default is 1.70158)</param>
/// <param name="period">Eventual period to use with Elastic easeType (default is 0)</param>
/// <param name="amplitude">Eventual amplitude to use with Elastic easeType or overshoot to use with Flash easeType (default is 1.70158).
/// <para>In case of Flash ease it sets the total number of flashes that will happen.
/// Using an even number will complete the tween on the starting value, while an odd one will complete it on the end value.</para>
/// </param>
/// <param name="period">Eventual period to use with Elastic or Flash easeType (default is 0).
/// <para>In case of Flash ease it indicates the power in time of the ease, and must be between -1 and 1.
/// 0 is balanced, 1 weakens the ease with time, -1 starts the ease weakened and gives it power towards the end.</para>
/// </param>
public static T SetEase<T>(this T t, Ease ease, float amplitude, float period) where T : Tween
{
if (t == null || !t.active) return t;

View File

@ -2040,16 +2040,22 @@
<summary>Sets the ease of the tween.
<para>If applied to Sequences eases the whole sequence animation</para></summary>
<param name="overshoot">
Eventual overshoot to use with Back ease (default is 1.70158).
Eventual overshoot to use with Back or Flash ease (default is 1.70158).
<para>In case of Flash ease it sets the total number of flashes that will happen.
Using an even number will end the tween on the starting value, while an odd one will end on the end value.</para>
Using an even number will complete the tween on the starting value, while an odd one will complete it on the end value.</para>
</param>
</member>
<member name="M:DG.Tweening.TweenSettingsExtensions.SetEase``1(``0,DG.Tweening.Ease,System.Single,System.Single)">
<summary>Sets the ease of the tween.
<para>If applied to Sequences eases the whole sequence animation</para></summary>
<param name="amplitude">Eventual amplitude to use with Elastic easeType (default is 1.70158)</param>
<param name="period">Eventual period to use with Elastic easeType (default is 0)</param>
<param name="amplitude">Eventual amplitude to use with Elastic easeType or overshoot to use with Flash easeType (default is 1.70158).
<para>In case of Flash ease it sets the total number of flashes that will happen.
Using an even number will complete the tween on the starting value, while an odd one will complete it on the end value.</para>
</param>
<param name="period">Eventual period to use with Elastic or Flash easeType (default is 0).
<para>In case of Flash ease it indicates the power in time of the ease, and must be between -1 and 1.
0 is balanced, 1 weakens the ease with time, -1 starts the ease weakened and gives it power towards the end.</para>
</param>
</member>
<member name="M:DG.Tweening.TweenSettingsExtensions.SetEase``1(``0,UnityEngine.AnimationCurve)">
<summary>Sets the ease of the tween using an AnimationCurve.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.