178 lines
6.7 KiB
C#
178 lines
6.7 KiB
C#
using UnityEngine;
|
||
|
||
namespace SLSUtilities.Feedback
|
||
{
|
||
/// <summary>
|
||
/// 震动曲线预设集合。每个方法返回一条全新的 AnimationCurve 实例。
|
||
/// 所有曲线的 X 轴为归一化时间 [0, 1],Y 轴为强度系数。
|
||
/// </summary>
|
||
public static class ShakeCurvePresets
|
||
{
|
||
/// <summary>
|
||
/// 预设名 → 工厂方法。
|
||
/// </summary>
|
||
public static readonly (string name, System.Func<AnimationCurve> factory)[] All = new[]
|
||
{
|
||
("Impact", (System.Func<AnimationCurve>)QuickImpact),
|
||
("Punch", (System.Func<AnimationCurve>)Punch),
|
||
("Bump", (System.Func<AnimationCurve>)SmoothBump),
|
||
("Fade Out", (System.Func<AnimationCurve>)FadeOut),
|
||
("Oscillate", (System.Func<AnimationCurve>)Oscillate),
|
||
("Dense Osc.", (System.Func<AnimationCurve>)DenseOscillate),
|
||
("Anticipation", (System.Func<AnimationCurve>)Anticipation),
|
||
("Recoil", (System.Func<AnimationCurve>)Recoil),
|
||
("Double Hit", (System.Func<AnimationCurve>)DoubleHit),
|
||
("Flash", (System.Func<AnimationCurve>)Flash),
|
||
};
|
||
|
||
/// <summary>
|
||
/// 快速冲击 — 峰值出现在 10~15%,之后快速衰减至零。
|
||
/// 适合:打击确认、子弹命中、轻攻击。
|
||
/// </summary>
|
||
public static AnimationCurve QuickImpact()
|
||
{
|
||
return new AnimationCurve(
|
||
new Keyframe(0f, 0f, 0f, 8f),
|
||
new Keyframe(0.12f, 1f, 0f, 0f),
|
||
new Keyframe(0.5f, 0.12f, -0.6f, -0.3f),
|
||
new Keyframe(1f, 0f, -0.1f, 0f)
|
||
);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 重拳 — 第 1 帧即达峰值,线性衰减至零。
|
||
/// 适合:重击、格挡冲击、爆炸瞬间。
|
||
/// </summary>
|
||
public static AnimationCurve Punch()
|
||
{
|
||
return new AnimationCurve(
|
||
new Keyframe(0f, 0f, 0f, float.PositiveInfinity),
|
||
new Keyframe(0.02f, 1f, 0f, -1.02f),
|
||
new Keyframe(1f, 0f, -1.02f, 0f)
|
||
);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 平滑铃形 — 对称的升/降曲线(EaseInOut)。
|
||
/// 适合:脚步震动、跳跃落地、节奏性效果。
|
||
/// </summary>
|
||
public static AnimationCurve SmoothBump()
|
||
{
|
||
return new AnimationCurve(
|
||
new Keyframe(0f, 0f, 0f, 0f),
|
||
new Keyframe(0.5f, 1f, 0f, 0f),
|
||
new Keyframe(1f, 0f, 0f, 0f)
|
||
);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 渐弱 — 起始即为峰值,EaseOut 衰减至零。
|
||
/// 适合:爆炸余波、效果消散、技能冷却过渡。
|
||
/// </summary>
|
||
public static AnimationCurve FadeOut()
|
||
{
|
||
return new AnimationCurve(
|
||
new Keyframe(0f, 1f, 0f, 0f),
|
||
new Keyframe(1f, 0f, -2f, 0f)
|
||
);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 衰减振荡 — 2~3 个波峰逐渐衰减。
|
||
/// 适合:爆炸余震、碰撞后振荡、弹跳。
|
||
/// </summary>
|
||
public static AnimationCurve Oscillate()
|
||
{
|
||
return new AnimationCurve(
|
||
new Keyframe(0f, 0f, 0f, 12f),
|
||
new Keyframe(0.08f, 1f, 0f, 0f),
|
||
new Keyframe(0.24f, -0.55f, 0f, 0f),
|
||
new Keyframe(0.42f, 0.3f, 0f, 0f),
|
||
new Keyframe(0.62f, -0.12f, 0f, 0f),
|
||
new Keyframe(1f, 0f, 0f, 0f)
|
||
);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 密集衰减振荡 — 5~6 个波峰,频率更高,适合更猛烈的效果。
|
||
/// 适合:大型爆炸持续余震、引擎振动、电击。
|
||
/// </summary>
|
||
public static AnimationCurve DenseOscillate()
|
||
{
|
||
return new AnimationCurve(
|
||
new Keyframe(0f, 0f, 0f, 20f),
|
||
new Keyframe(0.05f, 1f, 0f, 0f),
|
||
new Keyframe(0.13f, -0.72f, 0f, 0f),
|
||
new Keyframe(0.21f, 0.52f, 0f, 0f),
|
||
new Keyframe(0.29f, -0.36f, 0f, 0f),
|
||
new Keyframe(0.38f, 0.24f, 0f, 0f),
|
||
new Keyframe(0.48f, -0.15f, 0f, 0f),
|
||
new Keyframe(0.60f, 0.08f, 0f, 0f),
|
||
new Keyframe(0.75f, -0.03f, 0f, 0f),
|
||
new Keyframe(1f, 0f, 0f, 0f)
|
||
);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 预兆 + 冲击 — 先小幅反向蓄力,再大幅正向爆发。
|
||
/// 适合:重型近战预备 + 冲击,与动画预备帧配合。
|
||
/// </summary>
|
||
public static AnimationCurve Anticipation()
|
||
{
|
||
return new AnimationCurve(
|
||
new Keyframe(0f, 0f, 0f, 0f),
|
||
new Keyframe(0.18f, -0.2f, 0f, 0f),
|
||
new Keyframe(0.32f, 0f, 0f, 4f),
|
||
new Keyframe(0.5f, 1f, 0f, 0f),
|
||
new Keyframe(1f, 0f, -1.2f, 0f)
|
||
);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 后坐/反弹 — 快速达到峰值后超调回弹,逐渐收敛。
|
||
/// 适合:枪械后坐力、刀击挥出后的回摆。
|
||
/// </summary>
|
||
public static AnimationCurve Recoil()
|
||
{
|
||
return new AnimationCurve(
|
||
new Keyframe(0f, 0f, 0f, 10f),
|
||
new Keyframe(0.1f, 1f, 0f, 0f),
|
||
new Keyframe(0.32f, -0.3f, 0f, 0f),
|
||
new Keyframe(0.52f, 0.12f, 0f, 0f),
|
||
new Keyframe(0.72f, -0.04f, 0f, 0f),
|
||
new Keyframe(1f, 0f, 0f, 0f)
|
||
);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 双击峰 — 两个依次递减的波峰。
|
||
/// 适合:连击、二段攻击、双弹命中。
|
||
/// </summary>
|
||
public static AnimationCurve DoubleHit()
|
||
{
|
||
return new AnimationCurve(
|
||
new Keyframe(0f, 0f, 0f, 8f),
|
||
new Keyframe(0.12f, 1f, 0f, 0f),
|
||
new Keyframe(0.32f, 0.1f, 0f, 0f),
|
||
new Keyframe(0.52f, 0.7f, 0f, 0f),
|
||
new Keyframe(1f, 0f, -0.6f, 0f)
|
||
);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 方波闪光 — 近乎即时上升/下降,中间保持峰值。
|
||
/// 适合:描边闪光、即时视觉强调、全屏闪白。
|
||
/// </summary>
|
||
public static AnimationCurve Flash()
|
||
{
|
||
// 使用极陡切线模拟方波:在极短时间内完成升/降
|
||
return new AnimationCurve(
|
||
new Keyframe(0f, 0f, 0f, float.PositiveInfinity),
|
||
new Keyframe(0.02f, 1f, float.PositiveInfinity, 0f),
|
||
new Keyframe(0.98f, 1f, 0f, float.NegativeInfinity),
|
||
new Keyframe(1f, 0f, float.NegativeInfinity, 0f)
|
||
);
|
||
}
|
||
}
|
||
}
|