feat(ScreenGlitch): 完成基础的故障屏幕闪烁效果,并在重启时启用
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Core;
|
||||
using Script.Gameplay.Input;
|
||||
using UnityEngine;
|
||||
@@ -24,13 +25,16 @@ namespace Script.Gameplay.Global
|
||||
GameCountdownManager.Instance.StartLevelTimer();
|
||||
GameCountdownManager.Instance.OnFinish.AddListener(() =>
|
||||
{
|
||||
if (IsOpenRestartGameOnCountdownFinish) RestartGame();
|
||||
if (IsOpenRestartGameOnCountdownFinish)
|
||||
StartCoroutine(RestartGame());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public void RestartGame()
|
||||
public IEnumerator RestartGame()
|
||||
{
|
||||
StartCoroutine(ScreenGlitchManager.Instance.TriggerGlitchEffect());
|
||||
yield return new WaitForSeconds(1.0f);
|
||||
GameManager.Instance.ReStartGame();
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Script/Gameplay/Global/ScreenGlitchManager.cs.meta
Normal file
11
Assets/Script/Gameplay/Global/ScreenGlitchManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8ded342e0c632c44790b442a0305c440
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user