Files
ichni_Official/Assets/Scripts/Game/GameElements/GeneralEffects/ChromaticAberrationEffect.cs
SoulliesOfficial 25b6da25ae 同步
2026-03-31 07:51:40 -04:00

71 lines
2.4 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Ichni.RhythmGame.Beatmap;
using UnityEngine;
using UnityEngine.Rendering.Universal; // 需要引入 URP 库
namespace Ichni.RhythmGame
{
public class ChromaticAberrationEffect : EffectBase
{
#region [] Effect Parameters
public float peak;
public AnimationCurve intensityCurve;
// 缓存后处理组件,避免运行时每帧由于反序列化而产生 GC
private ChromaticAberration _chromaticAberration;
#endregion
#region [] Initialization
public ChromaticAberrationEffect(float effectTime, float peak, AnimationCurve intensityCurve)
: base(effectTime) // 【修改1】调用基类含时构造将 effectTime 赋为 duration激活时长逻辑
{
this.effectTime = effectTime;
this.peak = peak;
this.intensityCurve = intensityCurve;
}
/// <summary>
/// 私有方法:安全获取 URP 色差后处理句柄
/// </summary>
private void PrepareEffectHandle()
{
if (_chromaticAberration == null && PostProcessingManager.GlobalVolume != null)
{
// .profile 会自动实例化一个副本防止修改了Editor原有的资产
PostProcessingManager.GlobalVolume.profile.TryGet(out _chromaticAberration);
}
}
#endregion
#region [] Effect Pattern Overrides
public override void PreExecute()
{
PrepareEffectHandle();
}
public override void Execute()
{
if (_chromaticAberration != null)
{
// 【修改2】直接借助基类已算出的 effectProgressPercent 来拉取曲线
// 不再需要外部插件,每一帧的强度与音乐进程强绑定!哪怕音乐倒退也会原路倒退。
float currentIntensity = intensityCurve.Evaluate(effectProgressPercent) * peak;
_chromaticAberration.intensity.value = currentIntensity;
}
}
public override void Adjust() { ResetEffect(); }
public override void Recover() { ResetEffect(); }
public override void Disrupt() { ResetEffect(); }
private void ResetEffect()
{
if (_chromaticAberration != null) _chromaticAberration.intensity.value = 0f;
}
#endregion
}
}