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

82 lines
2.6 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
2026-07-09 17:10:17 -04:00
[Range(0f, 1f)] public float bottomX;
[Range(0f, 1f)] public float bottomY;
2025-07-10 08:42:30 -04:00
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
2026-03-31 07:51:40 -04:00
public PixelateEffect(float effectTime, float bottomX, float bottomY, AnimationCurve intensityCurve)
: base(effectTime) // 激活受控时间分段
2025-07-10 08:42:30 -04:00
{
2026-03-31 07:51:40 -04:00
this.effectTime = effectTime;
2026-07-09 17:10:17 -04:00
this.bottomX = Mathf.Clamp01(bottomX);
this.bottomY = Mathf.Clamp01(bottomY);
2025-07-10 08:42:30 -04:00
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;
2026-07-09 17:10:17 -04:00
_pixelateVolume.strengthX.value = 1f;
_pixelateVolume.strengthY.value = 1f;
2026-03-14 03:13:10 -04:00
}
2025-07-10 08:42:30 -04:00
}
public override void Execute()
{
2026-03-14 03:13:10 -04:00
if (_pixelateVolume != null)
{
2026-07-09 17:10:17 -04:00
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);
2026-03-14 03:13:10 -04:00
_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;
2026-07-09 17:10:17 -04:00
_pixelateVolume.strengthX.value = 1f;
_pixelateVolume.strengthY.value = 1f;
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
}
2026-03-31 07:51:40 -04:00