feat(ScreenGlitch): 完成基础的故障屏幕闪烁效果,并在重启时启用
This commit is contained in:
@@ -5,7 +5,8 @@
|
||||
"GUID:fd0e97c21c15497f9406b8ee23c1f67e",
|
||||
"GUID:75469ad4d38634e559750d17036d5f7c",
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23",
|
||||
"GUID:6055be8ebefd69e48b49212b09b47b2f"
|
||||
"GUID:6055be8ebefd69e48b49212b09b47b2f",
|
||||
"GUID:15fc0a57446b3144c949da3e2b9737a9"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
||||
@@ -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:
|
||||
@@ -41,7 +41,7 @@ namespace Script.Gameplay.Player
|
||||
|
||||
private void Start()
|
||||
{
|
||||
OnDeath += GameFlowManager.Instance.RestartGame;
|
||||
OnDeath += () => StartCoroutine(GameFlowManager.Instance.RestartGame());
|
||||
}
|
||||
|
||||
public void TakeDamage(int damage)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Script.Gameplay.Global;
|
||||
@@ -6,7 +7,7 @@ using TMPro;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class GameCountDownViewer : MonoBehaviour
|
||||
public class GameCountDownViewer : UIBase
|
||||
{
|
||||
public TMP_Text countdownText;
|
||||
private GameCountdownManager _countdownManager;
|
||||
|
||||
Reference in New Issue
Block a user