Files
2025TapTapGameJam/Assets/Script/Gameplay/Global/ScreenGlitchManager.cs

49 lines
1.5 KiB
C#

using System;
using System.Collections;
using Core;
using Cysharp.Threading.Tasks;
using Script.Gameplay.Input;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
namespace Script.Gameplay.Global
{
public class ScreenGlitchManager : MonoSingleton<ScreenGlitchManager>
{
[Tooltip("在 Project 中拖入 UniversalRendererData 资源")]
public UniversalRendererData rendererData;
[Tooltip("要控制的 RendererFeature 名称")] public string featureName = "ScreenGlitchFeature";
[SerializeField] private float glitchDuration = 1f;
public void SetFeatureActive(bool active)
{
if (rendererData == null)
{
Debug.LogError("rendererData 未赋值");
return;
}
foreach (var feature in rendererData.rendererFeatures)
{
if (feature != null && feature.name == featureName)
{
feature.SetActive(active);
Debug.Log($"{featureName} 已{(active ? "" : "")}");
return;
}
}
Debug.LogWarning($"未找到名为 {featureName} 的 RendererFeature");
}
// 使用协程,开启一段时间的故障效果,然后自动关闭
public IEnumerator TriggerGlitchEffect()
{
SetFeatureActive(true);
yield return new WaitForSeconds(glitchDuration);
SetFeatureActive(false);
}
}
}