feat(ScreenGlitch): 完成基础的故障屏幕闪烁效果,并在重启时启用
This commit is contained in:
49
Assets/Script/Gameplay/Global/ScreenGlitchManager.cs
Normal file
49
Assets/Script/Gameplay/Global/ScreenGlitchManager.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user