using Ichni.RhythmGame.Beatmap; using SLSUtilities.Rendering.PostProcessing; // 引入刚才写的 Volume 命名空间 using UnityEngine; namespace Ichni.RhythmGame { public class PixelateEffect : EffectBase { #region [效果参数] Effect Parameters public float duration; public float bottomX; public float bottomY; public AnimationCurve intensityCurve; private PixelateVolume _pixelateVolume; #endregion #region [初始化] Initialization public PixelateEffect(float duration, float bottomX, float bottomY, AnimationCurve intensityCurve) : base(duration) // 激活受控时间分段 { this.duration = duration; this.bottomX = bottomX; this.bottomY = bottomY; this.intensityCurve = intensityCurve; } private void PrepareHandle() { // 通过 Volume 体系接管控制权 if (_pixelateVolume == null && PostProcessingManager.GlobalVolume != null) { PostProcessingManager.GlobalVolume.profile.TryGet(out _pixelateVolume); } } #endregion #region [效果逻辑覆盖] Effect Pattern Overrides public override void PreExecute() { PrepareHandle(); if (_pixelateVolume != null) { _pixelateVolume.forceActive.value = true; _pixelateVolume.strengthX.value = Screen.width; _pixelateVolume.strengthY.value = Screen.height; } } public override void Execute() { if (_pixelateVolume != null) { float x = Mathf.Lerp(Screen.width, bottomX, intensityCurve.Evaluate(effectProgressPercent)); float y = Mathf.Lerp(Screen.height, bottomY, intensityCurve.Evaluate(effectProgressPercent)); _pixelateVolume.strengthX.value = x; _pixelateVolume.strengthY.value = y; } } public override void Adjust() { ResetEffect(); } public override void Recover() { ResetEffect(); } public override void Disrupt() { ResetEffect(); } private void ResetEffect() { if (_pixelateVolume != null) { _pixelateVolume.forceActive.value = false; _pixelateVolume.strengthX.value = Screen.width; _pixelateVolume.strengthY.value = Screen.height; } } #endregion } }