2023-02-27 07:32:26 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace SHADE_Scripting.UI
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
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-02-27 07:32:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class EasingHelper
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public static float EaseHelp(float value, EASING_METHOD method)
|
|
|
|
|
{
|
|
|
|
|
switch (method)
|
|
|
|
|
{
|
|
|
|
|
case EASING_METHOD.EASE_IN_SINE:
|
|
|
|
|
{
|
|
|
|
|
return EaseInSine(value);
|
|
|
|
|
}break;
|
|
|
|
|
case EASING_METHOD.EASE_OUT_SINE:
|
|
|
|
|
{
|
|
|
|
|
return EaseOutSine(value);
|
|
|
|
|
}break;
|
2023-02-27 15:16:48 +08:00
|
|
|
|
case EASING_METHOD.EASE_OUT_BOUNCE:
|
|
|
|
|
{
|
|
|
|
|
return EaseOutBounce(value);
|
|
|
|
|
}break;
|
|
|
|
|
case EASING_METHOD.EASE_IN_BOUNCE:
|
|
|
|
|
{
|
|
|
|
|
return EaseInBounce(value);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case EASING_METHOD.EASE_INOUT_BOUNCE:
|
|
|
|
|
{
|
|
|
|
|
return EaseInOutBounce(value);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2023-02-27 07:32:26 +08:00
|
|
|
|
default:
|
|
|
|
|
return 0.0f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static float EaseInSine(float value)
|
|
|
|
|
{
|
|
|
|
|
return (float)(1.0f - Math.Cos((value * Math.PI) / 2.0f));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static float EaseOutSine(float value)
|
|
|
|
|
{
|
|
|
|
|
return (float)(1.0f - Math.Sin(value * Math.PI) / 2.0f);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-27 15:16:48 +08:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
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-02-27 07:32:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|