Files
Cielonos/Assets/Scripts/MainGame/Effects/Feedbacks/Actions/VignetteAction.cs
SoulliesOfficial 41140a2017 新Feedback系统
2026-04-12 02:11:15 -04:00

148 lines
4.5 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 驱动 AdvancedVignette Volume 参数。
/// 可用于受击暗角、环境压抑等效果。
/// </summary>
[Serializable]
public class VignetteAction : CurveShakeAction
{
public override string DisplayName => "Vignette";
/// <summary>
/// 是否修改暗角中心点。
/// </summary>
[Title("Vignette Settings")]
[LabelText("Modify Center")]
public bool modifyCenter;
[ShowIf("modifyCenter")]
[LabelText("Center")]
public Vector2 center = new Vector2(0.5f, 0.5f);
/// <summary>
/// 是否修改颜色。
/// </summary>
[LabelText("Modify Colors")]
public bool modifyColors;
[ShowIf("modifyColors")]
[LabelText("Color Outer")]
public Color colorOuter = Color.black;
[ShowIf("modifyColors")]
[LabelText("Color Inner")]
public Color colorInner = Color.black;
/// <summary>
/// 是否修改柔和度和圆度。
/// </summary>
[LabelText("Modify Shape")]
public bool modifyShape;
[ShowIf("modifyShape")]
[LabelText("Smoothness")]
[Range(0.01f, 1f)]
public float smoothness = 0.5f;
[ShowIf("modifyShape")]
[LabelText("Roundness")]
[Range(0f, 1f)]
public float roundness = 1f;
[NonSerialized] private AdvancedVignette _vignette;
[NonSerialized] private float _initialIntensity;
[NonSerialized] private Vector2 _initialCenter;
[NonSerialized] private Color _initialColorOuter;
[NonSerialized] private Color _initialColorInner;
[NonSerialized] private float _initialSmoothness;
[NonSerialized] private float _initialRoundness;
[NonSerialized] private bool _resolved;
public override void OnStart(FeedbackContext context)
{
_resolved = TryResolveComponent();
if (!_resolved) return;
_initialIntensity = _vignette.intensity.value;
_initialCenter = _vignette.center.value;
_initialColorOuter = _vignette.colorOuter.value;
_initialColorInner = _vignette.colorInner.value;
_initialSmoothness = _vignette.smoothness.value;
_initialRoundness = _vignette.roundness.value;
if (modifyCenter)
_vignette.center.value = center;
if (modifyColors)
{
_vignette.colorOuter.value = colorOuter;
_vignette.colorInner.value = colorInner;
}
if (modifyShape)
{
_vignette.smoothness.value = smoothness;
_vignette.roundness.value = roundness;
}
}
public override void OnUpdate(FeedbackContext context, float normalizedTime)
{
if (!_resolved) return;
float newIntensity = EvaluateShake(normalizedTime, _initialIntensity);
_vignette.intensity.value = newIntensity;
}
public override void OnEnd(FeedbackContext context)
{
RestoreValues();
}
public override void OnInterrupt(FeedbackContext context)
{
RestoreValues();
}
private bool TryResolveComponent()
{
if (_vignette != null) return true;
if (PostProcessingManager.Instance == null)
{
Debug.LogWarning("[VignetteAction] PostProcessingManager instance not found.");
return false;
}
if (!PostProcessingManager.Instance.GetVolumeComponent(out _vignette))
{
Debug.LogWarning("[VignetteAction] AdvancedVignette not found in Volume Profile.");
return false;
}
return true;
}
private void RestoreValues()
{
if (!_resolved) return;
_vignette.intensity.value = _initialIntensity;
_vignette.center.value = _initialCenter;
_vignette.colorOuter.value = _initialColorOuter;
_vignette.colorInner.value = _initialColorInner;
_vignette.smoothness.value = _initialSmoothness;
_vignette.roundness.value = _initialRoundness;
_resolved = false;
}
}
}