Files
ichni_Official/Assets/Scripts/Game/GameElements/GeneralEffects/PixelateEffect.cs

80 lines
2.5 KiB
C#
Raw Normal View History

2025-07-10 08:42:30 -04:00
using Ichni.RhythmGame.Beatmap;
2026-03-14 03:13:10 -04:00
using SLSUtilities.Rendering.PostProcessing; // 引入刚才写的 Volume 命名空间
2025-07-10 08:42:30 -04:00
using UnityEngine;
namespace Ichni.RhythmGame
{
public class PixelateEffect : EffectBase
{
2026-03-14 03:13:10 -04:00
#region [] Effect Parameters
2025-07-10 08:42:30 -04:00
public float duration;
public float bottomX;
public float bottomY;
public AnimationCurve intensityCurve;
2026-03-14 03:13:10 -04:00
private PixelateVolume _pixelateVolume;
#endregion
2025-07-10 08:42:30 -04:00
2026-03-14 03:13:10 -04:00
#region [] Initialization
2025-07-10 08:42:30 -04:00
public PixelateEffect(float duration, float bottomX, float bottomY, AnimationCurve intensityCurve)
2026-03-14 03:13:10 -04:00
: base(duration) // 激活受控时间分段
2025-07-10 08:42:30 -04:00
{
this.duration = duration;
this.bottomX = bottomX;
this.bottomY = bottomY;
this.intensityCurve = intensityCurve;
}
2026-03-14 03:13:10 -04:00
private void PrepareHandle()
2025-07-10 08:42:30 -04:00
{
2026-03-14 03:13:10 -04:00
// 通过 Volume 体系接管控制权
if (_pixelateVolume == null && PostProcessingManager.GlobalVolume != null)
{
PostProcessingManager.GlobalVolume.profile.TryGet(out _pixelateVolume);
}
2025-07-10 08:42:30 -04:00
}
2026-03-14 03:13:10 -04:00
#endregion
#region [] Effect Pattern Overrides
2025-07-10 08:42:30 -04:00
public override void PreExecute()
{
2026-03-14 03:13:10 -04:00
PrepareHandle();
if (_pixelateVolume != null)
{
_pixelateVolume.forceActive.value = true;
_pixelateVolume.strengthX.value = Screen.width;
_pixelateVolume.strengthY.value = Screen.height;
}
2025-07-10 08:42:30 -04:00
}
public override void Execute()
{
2026-03-14 03:13:10 -04:00
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;
}
2025-07-10 08:42:30 -04:00
}
2026-03-14 03:13:10 -04:00
public override void Adjust() { ResetEffect(); }
public override void Recover() { ResetEffect(); }
public override void Disrupt() { ResetEffect(); }
2025-07-10 08:42:30 -04:00
2026-03-14 03:13:10 -04:00
private void ResetEffect()
2025-07-10 08:42:30 -04:00
{
2026-03-14 03:13:10 -04:00
if (_pixelateVolume != null)
2025-07-10 08:42:30 -04:00
{
2026-03-14 03:13:10 -04:00
_pixelateVolume.forceActive.value = false;
_pixelateVolume.strengthX.value = Screen.width;
_pixelateVolume.strengthY.value = Screen.height;
2025-07-10 08:42:30 -04:00
}
}
2026-03-14 03:13:10 -04:00
#endregion
2025-07-10 08:42:30 -04:00
}
2026-03-14 03:13:10 -04:00
}