166 lines
5.1 KiB
C#
166 lines
5.1 KiB
C#
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;
|
||
|
||
public FloatCurveChannel(AnimationCurve curve, float remapMin, float remapMax, bool relativeToInitial)
|
||
{
|
||
this.curve = curve;
|
||
this.remapMin = remapMin;
|
||
this.remapMax = remapMax;
|
||
this.relativeToInitial = relativeToInitial;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 创建默认的曲线通道。
|
||
/// </summary>
|
||
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
|
||
};
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据归一化时间计算当前值。
|
||
/// </summary>
|
||
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);
|
||
}
|
||
}
|
||
|
||
/// <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)
|
||
{
|
||
if (gradient == null) return Color.white;
|
||
return gradient.Evaluate(Mathf.Clamp01(normalizedTime));
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 带Vector2选项的曲线通道(用于中心点等)。
|
||
/// </summary>
|
||
[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;
|
||
|
||
/// <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>
|
||
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;
|
||
}
|
||
}
|
||
}
|