Files
ichni_Official/Assets/Scripts/Game/GameElements/GeneralEffects/PixelateEffect.cs
SoulliesOfficial 7580c4d87c 大更
2026-03-14 03:13:10 -04:00

80 lines
2.5 KiB
C#

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
}
}