2026-04-18 13:57:19 -04:00
|
|
|
|
using System;
|
|
|
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
|
|
using SLSUtilities.Feedback;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Cielonos.MainGame.Effects.Feedback
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 曲线通道模块,用于定义一个可复用的曲线震动参数。
|
|
|
|
|
|
/// 包含激活状态、曲线定义、重映射范围。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Serializable]
|
|
|
|
|
|
public struct FloatCurveChannel
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 震动曲线,X轴为归一化时间[0,1],Y轴为强度[0,1]。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[ShakeCurvePreset]
|
|
|
|
|
|
public AnimationCurve curve;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 曲线值0对应的实际数值。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[LabelText("Remap Min")]
|
|
|
|
|
|
public float remapMin;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 曲线值1对应的实际数值。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[LabelText("Remap Max")]
|
|
|
|
|
|
public float remapMax;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 是否相对初始值叠加。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Tooltip("开启时,结果叠加在初始值上;关闭时,结果为绝对值")]
|
|
|
|
|
|
public bool relativeToInitial;
|
|
|
|
|
|
|
2026-04-30 07:06:38 -04:00
|
|
|
|
public FloatCurveChannel(AnimationCurve curve, float remapMin, float remapMax, bool relativeToInitial)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.curve = curve;
|
|
|
|
|
|
this.remapMin = remapMin;
|
|
|
|
|
|
this.remapMax = remapMax;
|
|
|
|
|
|
this.relativeToInitial = relativeToInitial;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-18 13:57:19 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 创建默认的曲线通道。
|
|
|
|
|
|
/// </summary>
|
2026-04-28 15:46:32 -04:00
|
|
|
|
public static FloatCurveChannel CreateDefault(float remapMin = 0f, float remapMax = 1f, bool relativeToInitial = true)
|
2026-04-18 13:57:19 -04:00
|
|
|
|
{
|
|
|
|
|
|
return new FloatCurveChannel
|
|
|
|
|
|
{
|
|
|
|
|
|
curve = new AnimationCurve(
|
|
|
|
|
|
new Keyframe(0f, 0f),
|
|
|
|
|
|
new Keyframe(0.5f, 1f),
|
|
|
|
|
|
new Keyframe(1f, 0f)
|
|
|
|
|
|
),
|
|
|
|
|
|
remapMin = remapMin,
|
|
|
|
|
|
remapMax = remapMax,
|
|
|
|
|
|
relativeToInitial = relativeToInitial
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 根据归一化时间计算当前值。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public readonly float Evaluate(float normalizedTime)
|
|
|
|
|
|
{
|
2026-04-28 15:46:32 -04:00
|
|
|
|
if (curve == null) return 0f;
|
2026-04-18 13:57:19 -04:00
|
|
|
|
float t = Mathf.Clamp01(normalizedTime);
|
|
|
|
|
|
float curveValue = curve.Evaluate(t);
|
|
|
|
|
|
return Mathf.LerpUnclamped(remapMin, remapMax, curveValue);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 带颜色选项的曲线通道。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Serializable]
|
|
|
|
|
|
public struct ColorCurveChannel
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 颜色渐变。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[LabelText("颜色渐变")]
|
|
|
|
|
|
public Gradient gradient;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 创建默认的颜色曲线通道。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static ColorCurveChannel CreateDefault()
|
|
|
|
|
|
{
|
|
|
|
|
|
return new ColorCurveChannel
|
|
|
|
|
|
{
|
|
|
|
|
|
gradient = new Gradient()
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 根据归一化时间获取颜色。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Color Evaluate(float normalizedTime)
|
|
|
|
|
|
{
|
2026-04-28 15:46:32 -04:00
|
|
|
|
if (gradient == null) return Color.white;
|
2026-04-18 13:57:19 -04:00
|
|
|
|
return gradient.Evaluate(Mathf.Clamp01(normalizedTime));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 带Vector2选项的曲线通道(用于中心点等)。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Serializable]
|
|
|
|
|
|
public struct Vector2CurveChannel
|
|
|
|
|
|
{
|
|
|
|
|
|
[LabelText("曲线 X")]
|
|
|
|
|
|
[ShakeCurvePreset]
|
|
|
|
|
|
public AnimationCurve curveX;
|
2026-04-28 15:46:32 -04:00
|
|
|
|
|
2026-04-18 13:57:19 -04:00
|
|
|
|
[LabelText("曲线 Y")]
|
|
|
|
|
|
[ShakeCurvePreset]
|
|
|
|
|
|
public AnimationCurve curveY;
|
2026-04-28 15:46:32 -04:00
|
|
|
|
|
2026-04-18 13:57:19 -04:00
|
|
|
|
[LabelText("Remap Min")]
|
|
|
|
|
|
public Vector2 remapMin;
|
2026-04-28 15:46:32 -04:00
|
|
|
|
|
2026-04-18 13:57:19 -04:00
|
|
|
|
[LabelText("Remap Max")]
|
|
|
|
|
|
public Vector2 remapMax;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 是否相对初始值叠加。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[TitleGroup("高级设置")]
|
|
|
|
|
|
[LabelText("相对初始值")]
|
|
|
|
|
|
[Tooltip("开启时,结果叠加在初始值上;关闭时,结果为绝对值")]
|
|
|
|
|
|
public bool relativeToInitial;
|
|
|
|
|
|
|
|
|
|
|
|
public static Vector2CurveChannel CreateDefault()
|
|
|
|
|
|
{
|
|
|
|
|
|
return new Vector2CurveChannel
|
|
|
|
|
|
{
|
|
|
|
|
|
curveX = new AnimationCurve(new Keyframe(0f, 0f), new Keyframe(1f, 1f)),
|
|
|
|
|
|
curveY = new AnimationCurve(new Keyframe(0f, 0f), new Keyframe(1f, 1f)),
|
|
|
|
|
|
remapMin = Vector2.zero,
|
|
|
|
|
|
remapMax = Vector2.one
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 根据归一化时间计算Vector2值。
|
|
|
|
|
|
/// </summary>
|
2026-04-28 15:46:32 -04:00
|
|
|
|
public readonly Vector2 Evaluate(float normalizedTime, Vector2 initialValue)
|
2026-04-18 13:57:19 -04:00
|
|
|
|
{
|
|
|
|
|
|
float t = Mathf.Clamp01(normalizedTime);
|
|
|
|
|
|
float x = curveX?.Evaluate(t) ?? 0f;
|
|
|
|
|
|
float y = curveY?.Evaluate(t) ?? 0f;
|
|
|
|
|
|
Vector2 remappedValue = new Vector2(
|
|
|
|
|
|
Mathf.LerpUnclamped(remapMin.x, remapMax.x, x),
|
|
|
|
|
|
Mathf.LerpUnclamped(remapMin.y, remapMax.y, y)
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
return relativeToInitial ? initialValue + remappedValue : remappedValue;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|