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