127 lines
3.9 KiB
C#
127 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 驱动 AdvancedChromaticAberration Volume 参数。
|
|
/// </summary>
|
|
[Serializable]
|
|
public class ChromaticAberrationAction : CurveShakeAction
|
|
{
|
|
public override string DisplayName => "Chromatic Aberration";
|
|
|
|
/// <summary>
|
|
/// 是否同时修改中心点。
|
|
/// </summary>
|
|
[Title("Chromatic Aberration Settings")]
|
|
[LabelText("Modify Center")]
|
|
public bool modifyCenter;
|
|
|
|
[ShowIf("modifyCenter")]
|
|
[LabelText("Center")]
|
|
public Vector2 center = new Vector2(0.5f, 0.5f);
|
|
|
|
/// <summary>
|
|
/// 是否同时修改抖动强度。
|
|
/// </summary>
|
|
[LabelText("Modify Jitter")]
|
|
public bool modifyJitter;
|
|
|
|
[ShowIf("modifyJitter")]
|
|
[LabelText("Jitter Curve")]
|
|
public AnimationCurve jitterCurve = new AnimationCurve(
|
|
new Keyframe(0f, 0f),
|
|
new Keyframe(0.5f, 1f),
|
|
new Keyframe(1f, 0f)
|
|
);
|
|
|
|
[ShowIf("modifyJitter")]
|
|
[LabelText("Jitter Remap Min")]
|
|
public float jitterRemapMin;
|
|
|
|
[ShowIf("modifyJitter")]
|
|
[LabelText("Jitter Remap Max")]
|
|
public float jitterRemapMax = 0.5f;
|
|
|
|
[NonSerialized] private AdvancedChromaticAberration _aca;
|
|
[NonSerialized] private float _initialIntensity;
|
|
[NonSerialized] private Vector2 _initialCenter;
|
|
[NonSerialized] private float _initialJitter;
|
|
[NonSerialized] private bool _resolved;
|
|
|
|
public override void OnStart(FeedbackContext context)
|
|
{
|
|
_resolved = TryResolveComponent();
|
|
if (!_resolved) return;
|
|
|
|
_initialIntensity = _aca.intensity.value;
|
|
_initialCenter = _aca.center.value;
|
|
_initialJitter = _aca.jitterIntensity.value;
|
|
|
|
if (modifyCenter)
|
|
{
|
|
_aca.center.value = center;
|
|
}
|
|
}
|
|
|
|
public override void OnUpdate(FeedbackContext context, float normalizedTime)
|
|
{
|
|
if (!_resolved) return;
|
|
|
|
float newIntensity = EvaluateShake(normalizedTime, _initialIntensity);
|
|
_aca.intensity.value = newIntensity;
|
|
|
|
if (modifyJitter)
|
|
{
|
|
float jitterValue = jitterCurve.Evaluate(normalizedTime);
|
|
float mappedJitter = Mathf.LerpUnclamped(jitterRemapMin, jitterRemapMax, jitterValue);
|
|
_aca.jitterIntensity.value = relativeToInitial ? _initialJitter + mappedJitter : mappedJitter;
|
|
}
|
|
}
|
|
|
|
public override void OnEnd(FeedbackContext context)
|
|
{
|
|
RestoreValues();
|
|
}
|
|
|
|
public override void OnInterrupt(FeedbackContext context)
|
|
{
|
|
RestoreValues();
|
|
}
|
|
|
|
private bool TryResolveComponent()
|
|
{
|
|
if (_aca != null) return true;
|
|
|
|
if (PostProcessingManager.Instance == null)
|
|
{
|
|
Debug.LogWarning("[ChromaticAberrationAction] PostProcessingManager instance not found.");
|
|
return false;
|
|
}
|
|
|
|
if (!PostProcessingManager.Instance.GetVolumeComponent(out _aca))
|
|
{
|
|
Debug.LogWarning("[ChromaticAberrationAction] AdvancedChromaticAberration not found in Volume Profile.");
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
private void RestoreValues()
|
|
{
|
|
if (!_resolved) return;
|
|
|
|
_aca.intensity.value = _initialIntensity;
|
|
_aca.center.value = _initialCenter;
|
|
_aca.jitterIntensity.value = _initialJitter;
|
|
_resolved = false;
|
|
}
|
|
}
|
|
}
|