feat(Cycle):实现循环提前检测,修复交互提示消失,按键绑定的事件在重启的时候没能正确,触发循环的提前检测有错误
This commit is contained in:
85
Assets/Script/Gameplay/Global/BUGManager.cs
Normal file
85
Assets/Script/Gameplay/Global/BUGManager.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace Script.Gameplay.Global
|
||||
{
|
||||
public struct StackOverflowBUGLog
|
||||
{
|
||||
public Transform TargetTransform;
|
||||
public int BeTriggerCycle; // 触发时的游戏循环次数
|
||||
|
||||
public StackOverflowBUGLog(Transform targetTransform, int beTriggerCycle)
|
||||
{
|
||||
TargetTransform = targetTransform;
|
||||
BeTriggerCycle = beTriggerCycle;
|
||||
}
|
||||
}
|
||||
|
||||
public class BUGManager : MonoSingleton<BUGManager>
|
||||
{
|
||||
[SerializeField] private GameObject bugCubePrefab;
|
||||
|
||||
[Header("天核区域检测设置")] [SerializeField] private Vector3 AreaCenter = Vector3.zero;
|
||||
[SerializeField] private Vector3 AreaSize = new Vector3(50, 50, 50);
|
||||
public UnityEvent OnBUGHappenedInArea;
|
||||
|
||||
private List<StackOverflowBUGLog> stackOverflowBugLogs = new List<StackOverflowBUGLog>();
|
||||
private List<GameObject> bugCubes = new List<GameObject>();
|
||||
|
||||
private void Start()
|
||||
{
|
||||
OnBUGHappenedInArea.AddListener(() =>
|
||||
{
|
||||
Debug.LogWarning("天核区域内检测到BUG立方体!");
|
||||
});
|
||||
|
||||
GameManager.Instance.OnGameStart += GenerateBUGCubes;
|
||||
}
|
||||
|
||||
public void LogStackOverflowBUG(Transform targetTransform)
|
||||
{
|
||||
int beTriggerCycle = GameDataManager.Instance.TotalLoopCount;
|
||||
stackOverflowBugLogs.Add(new StackOverflowBUGLog(targetTransform, beTriggerCycle));
|
||||
GameManager.Instance.ReStartGame();
|
||||
}
|
||||
|
||||
public void GenerateBUGCubes()
|
||||
{
|
||||
bugCubes.Clear();
|
||||
int currentCycle = GameDataManager.Instance.TotalLoopCount;
|
||||
|
||||
// 记录的BUG位置生成BUG立方体
|
||||
foreach (var log in stackOverflowBugLogs)
|
||||
{
|
||||
if (bugCubePrefab != null)
|
||||
{
|
||||
// 仅在下一次循环生成BUG立方体
|
||||
if (log.BeTriggerCycle + 1 != currentCycle) continue;
|
||||
GameObject go = Instantiate(bugCubePrefab, log.TargetTransform.position, Quaternion.identity);
|
||||
bugCubes.Add(go);
|
||||
}
|
||||
}
|
||||
|
||||
// 检测天核区域内是否有BUG立方体
|
||||
Collider[] colliders = Physics.OverlapBox(AreaCenter, AreaSize * 0.5f);
|
||||
foreach (var collider in colliders)
|
||||
{
|
||||
if (bugCubes.Contains(collider.gameObject))
|
||||
{
|
||||
OnBUGHappenedInArea?.Invoke();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 可视化天核区域
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
Gizmos.color = new Color(1, 0, 0, 0.3f);
|
||||
Gizmos.DrawCube(AreaCenter, AreaSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user