116 lines
3.7 KiB
C#
116 lines
3.7 KiB
C#
using System;
|
||
using Cielonos;
|
||
using Sirenix.OdinInspector;
|
||
using SLSUtilities.Feedback;
|
||
using SLSUtilities.Rendering.PostProcessing;
|
||
using UnityEngine;
|
||
|
||
namespace Cielonos.MainGame.Effects.Feedback
|
||
{
|
||
/// <summary>
|
||
/// 黑白闪反馈动作,在 Clip 持续时间内开启 StrobeFlash 的 AutoFlash,
|
||
/// Clip 结束或被打断时自动关闭。
|
||
/// </summary>
|
||
[Serializable]
|
||
public class StrobeFlashAction : FeedbackActionBase
|
||
{
|
||
public override string DisplayName => "Strobe Flash";
|
||
|
||
/// <summary>
|
||
/// 是否修改频率和颜色参数。
|
||
/// </summary>
|
||
[Title("Strobe Settings")]
|
||
[LabelText("Modify Extra")]
|
||
public bool modifyExtra;
|
||
|
||
[ShowIf("modifyExtra")]
|
||
[LabelText("Frequency")]
|
||
public float frequency = 15f;
|
||
|
||
[ShowIf("modifyExtra")]
|
||
[LabelText("Color High")]
|
||
public Color colorHigh = Color.white;
|
||
|
||
[ShowIf("modifyExtra")]
|
||
[LabelText("Color Low")]
|
||
public Color colorLow = Color.black;
|
||
|
||
[NonSerialized] private StrobeFlash _strobeFlash;
|
||
[NonSerialized] private bool _initialEnable;
|
||
[NonSerialized] private bool _initialAutoFlash;
|
||
[NonSerialized] private float _initialFrequency;
|
||
[NonSerialized] private Color _initialColorHigh;
|
||
[NonSerialized] private Color _initialColorLow;
|
||
[NonSerialized] private bool _resolved;
|
||
|
||
public override void OnStart(FeedbackContext context)
|
||
{
|
||
_resolved = TryResolveComponent();
|
||
if (!_resolved) return;
|
||
|
||
_initialEnable = _strobeFlash.enableEffect.value;
|
||
_initialAutoFlash = _strobeFlash.autoFlash.value;
|
||
_initialFrequency = _strobeFlash.frequency.value;
|
||
_initialColorHigh = _strobeFlash.colorHigh.value;
|
||
_initialColorLow = _strobeFlash.colorLow.value;
|
||
|
||
_strobeFlash.enableEffect.value = true;
|
||
_strobeFlash.autoFlash.value = true;
|
||
|
||
if (modifyExtra)
|
||
{
|
||
_strobeFlash.frequency.value = frequency;
|
||
_strobeFlash.colorHigh.value = colorHigh;
|
||
_strobeFlash.colorLow.value = colorLow;
|
||
}
|
||
}
|
||
|
||
public override void OnUpdate(FeedbackContext context, float normalizedTime)
|
||
{
|
||
// StrobeFlash 由 Shader 内部的 _Time 驱动自动闪烁,
|
||
// Action 只负责开关控制,不需要每帧更新。
|
||
}
|
||
|
||
public override void OnEnd(FeedbackContext context)
|
||
{
|
||
RestoreValues();
|
||
}
|
||
|
||
public override void OnInterrupt(FeedbackContext context)
|
||
{
|
||
RestoreValues();
|
||
}
|
||
|
||
private bool TryResolveComponent()
|
||
{
|
||
if (_strobeFlash != null) return true;
|
||
|
||
if (PostProcessingManager.Instance == null)
|
||
{
|
||
Debug.LogWarning("[StrobeFlashAction] PostProcessingManager instance not found.");
|
||
return false;
|
||
}
|
||
|
||
if (!PostProcessingManager.Instance.GetVolumeComponent(out _strobeFlash))
|
||
{
|
||
Debug.LogWarning("[StrobeFlashAction] StrobeFlash not found in Volume Profile.");
|
||
return false;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
private void RestoreValues()
|
||
{
|
||
if (!_resolved) return;
|
||
|
||
_strobeFlash.enableEffect.value = _initialEnable;
|
||
_strobeFlash.autoFlash.value = _initialAutoFlash;
|
||
_strobeFlash.frequency.value = _initialFrequency;
|
||
_strobeFlash.colorHigh.value = _initialColorHigh;
|
||
_strobeFlash.colorLow.value = _initialColorLow;
|
||
_resolved = false;
|
||
}
|
||
}
|
||
}
|