2025-10-27 10:31:01 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using Core;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.Events;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Script.Gameplay.Global
|
|
|
|
|
|
{
|
2025-10-28 10:10:41 +08:00
|
|
|
|
public struct TransformSnapshot
|
|
|
|
|
|
{
|
|
|
|
|
|
public Vector3 Position;
|
|
|
|
|
|
public Quaternion Rotation;
|
|
|
|
|
|
public Vector3 Scale;
|
|
|
|
|
|
|
|
|
|
|
|
public TransformSnapshot(Transform t)
|
|
|
|
|
|
{
|
|
|
|
|
|
Position = t.position;
|
|
|
|
|
|
Rotation = t.rotation;
|
|
|
|
|
|
Scale = t.localScale;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-27 10:31:01 +08:00
|
|
|
|
public struct StackOverflowBUGLog
|
|
|
|
|
|
{
|
2025-10-28 10:10:41 +08:00
|
|
|
|
public TransformSnapshot TargetSnapshot;
|
2025-10-27 10:31:01 +08:00
|
|
|
|
public int BeTriggerCycle; // 触发时的游戏循环次数
|
|
|
|
|
|
|
|
|
|
|
|
public StackOverflowBUGLog(Transform targetTransform, int beTriggerCycle)
|
|
|
|
|
|
{
|
2025-10-28 10:10:41 +08:00
|
|
|
|
TargetSnapshot = new TransformSnapshot(targetTransform);
|
2025-10-27 10:31:01 +08:00
|
|
|
|
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);
|
2025-10-28 10:10:41 +08:00
|
|
|
|
public UnityEvent OnBugHappenedInArea;
|
2025-10-27 10:31:01 +08:00
|
|
|
|
|
|
|
|
|
|
private List<StackOverflowBUGLog> stackOverflowBugLogs = new List<StackOverflowBUGLog>();
|
|
|
|
|
|
private List<GameObject> bugCubes = new List<GameObject>();
|
|
|
|
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
|
|
{
|
2025-10-30 17:51:17 +08:00
|
|
|
|
OnBugHappenedInArea.AddListener(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
GameManager.Instance.EndGameplay();
|
|
|
|
|
|
Debug.Log("天核区域内检测到BUG立方体!");
|
|
|
|
|
|
});
|
2025-10-28 10:10:41 +08:00
|
|
|
|
|
|
|
|
|
|
GameManager.Instance.OnGameStart += GenerateBugCubes;
|
2025-10-27 10:31:01 +08:00
|
|
|
|
}
|
2025-10-28 10:10:41 +08:00
|
|
|
|
|
2025-10-27 10:31:01 +08:00
|
|
|
|
|
2025-10-28 10:10:41 +08:00
|
|
|
|
public void LogStackOverflowBug(Transform targetTransform)
|
2025-10-27 10:31:01 +08:00
|
|
|
|
{
|
|
|
|
|
|
int beTriggerCycle = GameDataManager.Instance.TotalLoopCount;
|
|
|
|
|
|
stackOverflowBugLogs.Add(new StackOverflowBUGLog(targetTransform, beTriggerCycle));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-28 10:10:41 +08:00
|
|
|
|
public void GenerateBugCubes()
|
2025-10-27 10:31:01 +08:00
|
|
|
|
{
|
2025-10-28 10:10:41 +08:00
|
|
|
|
foreach (var bugCube in bugCubes)
|
|
|
|
|
|
{
|
|
|
|
|
|
Destroy(bugCube);
|
|
|
|
|
|
}
|
2025-10-27 10:31:01 +08:00
|
|
|
|
bugCubes.Clear();
|
|
|
|
|
|
int currentCycle = GameDataManager.Instance.TotalLoopCount;
|
2025-10-28 10:10:41 +08:00
|
|
|
|
|
2025-10-27 10:31:01 +08:00
|
|
|
|
// 记录的BUG位置生成BUG立方体
|
|
|
|
|
|
foreach (var log in stackOverflowBugLogs)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (bugCubePrefab != null)
|
|
|
|
|
|
{
|
2025-10-28 10:10:41 +08:00
|
|
|
|
// 仅在下一、二次循环生成BUG立方体
|
|
|
|
|
|
if (currentCycle - log.BeTriggerCycle >= 0 && currentCycle - log.BeTriggerCycle < 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
GameObject go = Instantiate(bugCubePrefab, log.TargetSnapshot.Position, Quaternion.identity);
|
|
|
|
|
|
bugCubes.Add(go);
|
|
|
|
|
|
}
|
2025-10-27 10:31:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-10-28 10:10:41 +08:00
|
|
|
|
|
2025-10-27 10:31:01 +08:00
|
|
|
|
// 检测天核区域内是否有BUG立方体
|
|
|
|
|
|
Collider[] colliders = Physics.OverlapBox(AreaCenter, AreaSize * 0.5f);
|
|
|
|
|
|
foreach (var collider in colliders)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (bugCubes.Contains(collider.gameObject))
|
|
|
|
|
|
{
|
2025-10-28 10:10:41 +08:00
|
|
|
|
OnBugHappenedInArea?.Invoke();
|
2025-10-27 10:31:01 +08:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-10-28 10:10:41 +08:00
|
|
|
|
|
2025-10-27 10:31:01 +08:00
|
|
|
|
// 可视化天核区域
|
|
|
|
|
|
private void OnDrawGizmosSelected()
|
|
|
|
|
|
{
|
|
|
|
|
|
Gizmos.color = new Color(1, 0, 0, 0.3f);
|
|
|
|
|
|
Gizmos.DrawCube(AreaCenter, AreaSize);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|