SHADE_Y3/Assets/Scripts/UI/EasingHelper.cs

101 lines
1.9 KiB
C#
Raw Permalink Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public enum EASING_METHOD
{
EASE_IN_SINE,
EASE_OUT_SINE,
2023-02-27 15:16:48 +08:00
EASE_OUT_BOUNCE,
EASE_IN_BOUNCE,
EASE_INOUT_BOUNCE
}
2023-03-08 18:49:36 +08:00
public static class EasingHelper
{
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-03-08 18:49:36 +08:00
return EaseInSine(value);
}
2023-03-08 18:49:36 +08:00
break;
case EASING_METHOD.EASE_OUT_SINE:
{
2023-03-08 18:49:36 +08:00
return EaseOutSine(value);
}
2023-03-08 18:49:36 +08:00
break;
case EASING_METHOD.EASE_OUT_BOUNCE:
{
2023-03-08 18:49:36 +08:00
return EaseOutBounce(value);
}
2023-03-08 18:49:36 +08:00
break;
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-03-08 18:49:36 +08:00
break;
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-03-08 18:49:36 +08:00
break;
default:
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-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-03-08 18:49:36 +08:00