Files
ichni_Official/Assets/Scripts/Game/GameElements/GeneralEffects/PixelateEffect.cs
2026-07-09 17:10:17 -04:00

82 lines
2.6 KiB
C#

using Ichni.RhythmGame.Beatmap;
using SLSUtilities.Rendering.PostProcessing; // 引入刚才写的 Volume 命名空间
using UnityEngine;
namespace Ichni.RhythmGame
{
public class PixelateEffect : EffectBase
{
#region [] Effect Parameters
[Range(0f, 1f)] public float bottomX;
[Range(0f, 1f)] public float bottomY;
public AnimationCurve intensityCurve;
private PixelateVolume _pixelateVolume;
#endregion
#region [] Initialization
public PixelateEffect(float effectTime, float bottomX, float bottomY, AnimationCurve intensityCurve)
: base(effectTime) // 激活受控时间分段
{
this.effectTime = effectTime;
this.bottomX = Mathf.Clamp01(bottomX);
this.bottomY = Mathf.Clamp01(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 = 1f;
_pixelateVolume.strengthY.value = 1f;
}
}
public override void Execute()
{
if (_pixelateVolume != null)
{
float progress = intensityCurve == null ? effectProgressPercent : intensityCurve.Evaluate(effectProgressPercent);
float x = Mathf.Lerp(1f, Mathf.Clamp01(bottomX), progress);
float y = Mathf.Lerp(1f, Mathf.Clamp01(bottomY), progress);
_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 = 1f;
_pixelateVolume.strengthY.value = 1f;
}
}
#endregion
}
}