2023-02-27 07:32:26 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2023-04-01 16:08:32 +08:00
|
|
|
|
public enum EASING_METHOD
|
|
|
|
|
{
|
|
|
|
|
EASE_IN_SINE,
|
|
|
|
|
EASE_OUT_SINE,
|
|
|
|
|
EASE_OUT_BOUNCE,
|
|
|
|
|
EASE_IN_BOUNCE,
|
|
|
|
|
EASE_INOUT_BOUNCE,
|
|
|
|
|
EASE_OUT_CIRCLE,
|
|
|
|
|
EASE_OUT_BACK,
|
|
|
|
|
LINEAR
|
|
|
|
|
}
|
2023-02-27 07:32:26 +08:00
|
|
|
|
|
2023-03-08 18:49:36 +08:00
|
|
|
|
public static class EasingHelper
|
|
|
|
|
{
|
2023-02-27 07:32:26 +08:00
|
|
|
|
|
2023-03-08 18:49:36 +08:00
|
|
|
|
public static float EaseHelp(float value, EASING_METHOD method)
|
|
|
|
|
{
|
|
|
|
|
switch (method)
|
|
|
|
|
{
|
|
|
|
|
case EASING_METHOD.EASE_IN_SINE:
|
2023-02-27 07:32:26 +08:00
|
|
|
|
{
|
2023-03-08 18:49:36 +08:00
|
|
|
|
return EaseInSine(value);
|
2023-02-27 07:32:26 +08:00
|
|
|
|
}
|
2023-04-01 16:08:32 +08:00
|
|
|
|
|
2023-03-08 18:49:36 +08:00
|
|
|
|
case EASING_METHOD.EASE_OUT_SINE:
|
2023-02-27 07:32:26 +08:00
|
|
|
|
{
|
2023-03-08 18:49:36 +08:00
|
|
|
|
return EaseOutSine(value);
|
2023-02-27 07:32:26 +08:00
|
|
|
|
}
|
2023-04-01 16:08:32 +08:00
|
|
|
|
|
2023-03-08 18:49:36 +08:00
|
|
|
|
case EASING_METHOD.EASE_OUT_BOUNCE:
|
2023-02-27 07:32:26 +08:00
|
|
|
|
{
|
2023-03-08 18:49:36 +08:00
|
|
|
|
return EaseOutBounce(value);
|
2023-02-27 07:32:26 +08:00
|
|
|
|
}
|
2023-04-01 16:08:32 +08:00
|
|
|
|
|
2023-03-08 18:49:36 +08:00
|
|
|
|
case EASING_METHOD.EASE_IN_BOUNCE:
|
2023-02-27 15:16:48 +08:00
|
|
|
|
{
|
2023-03-08 18:49:36 +08:00
|
|
|
|
return EaseInBounce(value);
|
2023-02-27 15:16:48 +08:00
|
|
|
|
}
|
2023-04-01 16:08:32 +08:00
|
|
|
|
|
2023-03-08 18:49:36 +08:00
|
|
|
|
case EASING_METHOD.EASE_INOUT_BOUNCE:
|
2023-02-27 15:16:48 +08:00
|
|
|
|
{
|
2023-03-08 18:49:36 +08:00
|
|
|
|
return EaseInOutBounce(value);
|
2023-02-27 15:16:48 +08:00
|
|
|
|
}
|
2023-04-01 16:08:32 +08:00
|
|
|
|
|
2023-03-20 15:55:50 +08:00
|
|
|
|
case EASING_METHOD.LINEAR:
|
2023-04-01 16:08:32 +08:00
|
|
|
|
{
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
case EASING_METHOD.EASE_OUT_CIRCLE:
|
|
|
|
|
{
|
|
|
|
|
return EaseOutCircle(value);
|
|
|
|
|
}
|
|
|
|
|
case EASING_METHOD.EASE_OUT_BACK:
|
|
|
|
|
{
|
|
|
|
|
return EaseOutBack(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
2023-03-08 18:49:36 +08:00
|
|
|
|
return 0.0f;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-02-27 15:16:48 +08:00
|
|
|
|
|
2023-03-08 18:49:36 +08:00
|
|
|
|
private static float EaseInSine(float value)
|
|
|
|
|
{
|
2023-02-27 15:16:48 +08:00
|
|
|
|
|
2023-03-08 18:49:36 +08:00
|
|
|
|
return (float)(1.0f - Math.Cos((value * Math.PI / 2.0f)));
|
2023-02-27 15:16:48 +08:00
|
|
|
|
|
2023-03-08 18:49:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static float EaseOutSine(float value)
|
|
|
|
|
{
|
|
|
|
|
return (float)(Math.Sin(value * Math.PI / 2.0f));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static float EaseOutBounce(float value)
|
|
|
|
|
{
|
|
|
|
|
const float n1 = 7.5625f;
|
|
|
|
|
const float d1 = 2.75f;
|
|
|
|
|
if (value < 1.0f / d1)
|
|
|
|
|
{
|
|
|
|
|
return n1 * value * value;
|
|
|
|
|
}
|
|
|
|
|
else if (value < 2.0f / d1)
|
|
|
|
|
{
|
|
|
|
|
return n1 * (value -= 2.25f / d1) * value + 0.9375f;
|
2023-02-27 07:32:26 +08:00
|
|
|
|
}
|
2023-03-08 18:49:36 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return n1 * (value -= 2.625f / d1) * value + 0.984375f;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static float EaseInBounce(float value)
|
|
|
|
|
{
|
|
|
|
|
return 1 - EaseOutBounce(1 - value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static float EaseInOutBounce(float value)
|
|
|
|
|
{
|
|
|
|
|
return (value < 0.5f)
|
|
|
|
|
? (1.0f - EaseOutBounce(1.0f - 2.0f * value)) / 2.0f
|
|
|
|
|
: (1.0f + EaseOutBounce(2.0f * value - 1.0f)) / 2.0f;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-01 16:08:32 +08:00
|
|
|
|
|
|
|
|
|
private static float EaseOutCircle(float value)
|
|
|
|
|
{
|
|
|
|
|
return (float)Math.Sqrt(1.0f - (float)Math.Pow(value - 1.0f, 2.0f));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static float EaseOutBack(float value)
|
|
|
|
|
{
|
|
|
|
|
const float c1 = 1.70158f;
|
|
|
|
|
const float c3 = c1 + 1.0f;
|
|
|
|
|
return 1.0f + c3 * (float)Math.Pow(value - 1.0f, 3.0f) + c1 * (float)Math.Pow(value - 1.0f, 2.0f);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-27 07:32:26 +08:00
|
|
|
|
}
|
2023-03-08 18:49:36 +08:00
|
|
|
|
|