124 lines
3.9 KiB
C#
124 lines
3.9 KiB
C#
using System;
|
|
using Cielonos;
|
|
using Sirenix.OdinInspector;
|
|
using SLSUtilities.Feedback;
|
|
using SLSUtilities.Rendering.PostProcessing;
|
|
using UnityEngine;
|
|
|
|
namespace Cielonos.MainGame.Effects.Feedback
|
|
{
|
|
/// <summary>
|
|
/// 径向模糊反馈动作,通过 PostProcessingManager 驱动 RadialBlur Volume 参数。
|
|
/// 继承 CurveShakeAction 获得曲线采样和初始值管理能力。
|
|
/// </summary>
|
|
[Serializable]
|
|
public class RadialBlurAction : CurveShakeAction
|
|
{
|
|
public override string DisplayName => "Radial Blur";
|
|
|
|
/// <summary>
|
|
/// 是否修改模糊中心点。关闭时保持 Volume 当前设置(通常为 0.5, 0.5)。
|
|
/// </summary>
|
|
[Title("Radial Blur Settings")]
|
|
[LabelText("Modify Center")]
|
|
public bool modifyCenter;
|
|
|
|
/// <summary>
|
|
/// 模糊中心的屏幕坐标 (0-1)。(0.5, 0.5) 为屏幕正中心。
|
|
/// </summary>
|
|
[ShowIf("modifyCenter")]
|
|
[LabelText("Center")]
|
|
public Vector2 center = new Vector2(0.5f, 0.5f);
|
|
|
|
// 运行时缓存
|
|
[NonSerialized] private RadialBlur _radialBlur;
|
|
[NonSerialized] private float _initialBlurRadius;
|
|
[NonSerialized] private float _initialCenterX;
|
|
[NonSerialized] private float _initialCenterY;
|
|
[NonSerialized] private bool _resolved;
|
|
|
|
public override void OnStart(FeedbackContext context)
|
|
{
|
|
_resolved = TryResolveComponent();
|
|
if (!_resolved) return;
|
|
|
|
// 记录初始值用于复位
|
|
_initialBlurRadius = _radialBlur.blurRadius.value;
|
|
_initialCenterX = _radialBlur.radialCenterX.value;
|
|
_initialCenterY = _radialBlur.radialCenterY.value;
|
|
|
|
// 设置中心点(整个 Clip 期间保持不变)
|
|
if (modifyCenter)
|
|
{
|
|
_radialBlur.radialCenterX.value = center.x;
|
|
_radialBlur.radialCenterY.value = center.y;
|
|
}
|
|
}
|
|
|
|
public override void OnUpdate(FeedbackContext context, float normalizedTime)
|
|
{
|
|
if (!_resolved) return;
|
|
|
|
float newRadius = EvaluateShake(normalizedTime, _initialBlurRadius);
|
|
_radialBlur.blurRadius.value = newRadius;
|
|
}
|
|
|
|
public override void OnEnd(FeedbackContext context)
|
|
{
|
|
RestoreValues();
|
|
}
|
|
|
|
public override void OnInterrupt(FeedbackContext context)
|
|
{
|
|
RestoreValues();
|
|
}
|
|
|
|
public override bool Validate(out string error)
|
|
{
|
|
if (PostProcessingManager.Instance == null)
|
|
{
|
|
error = "PostProcessingManager instance not found in scene.";
|
|
return false;
|
|
}
|
|
|
|
error = null;
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 尝试从 PostProcessingManager 获取 RadialBlur Volume 组件。
|
|
/// </summary>
|
|
private bool TryResolveComponent()
|
|
{
|
|
if (_radialBlur != null) return true;
|
|
|
|
if (PostProcessingManager.Instance == null)
|
|
{
|
|
Debug.LogWarning("[RadialBlurAction] PostProcessingManager instance not found.");
|
|
return false;
|
|
}
|
|
|
|
if (!PostProcessingManager.Instance.GetVolumeComponent(out _radialBlur))
|
|
{
|
|
Debug.LogWarning("[RadialBlurAction] RadialBlur component not found in Volume Profile.");
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 恢复到 OnStart 时记录的初始值。
|
|
/// </summary>
|
|
private void RestoreValues()
|
|
{
|
|
if (!_resolved) return;
|
|
|
|
_radialBlur.blurRadius.value = _initialBlurRadius;
|
|
_radialBlur.radialCenterX.value = _initialCenterX;
|
|
_radialBlur.radialCenterY.value = _initialCenterY;
|
|
_resolved = false;
|
|
}
|
|
}
|
|
}
|