feat(BUGCube):实现BUG位置生成异常方块

This commit is contained in:
2025-10-28 10:10:41 +08:00
parent da4edb55a8
commit 7fdd7a1bb1
11 changed files with 5687 additions and 27 deletions

View File

@@ -75,12 +75,12 @@ namespace Script.Gameplay.Connect
var connectionLine = GenerateConnectionLine(source, target);
if (connectionLine == null)
{
Debug.Log($"编号为{preConnection.PreConnectionID}的连接线存在重复连接,生成失败");
Debug.LogWarning($"编号为{preConnection.PreConnectionID}的连接线存在重复连接,生成失败");
}
}
else
{
Debug.Log($"编号为{preConnection.PreConnectionID}的连接线的配置错误,生成失败");
Debug.LogWarning($"编号为{preConnection.PreConnectionID}的连接线的配置错误,生成失败");
}
}
}

View File

@@ -149,6 +149,7 @@ namespace Script.Gameplay.Facility
// 利用DFS检测是否存在连接环
if (DfsCheckConnectionRing(this.gameObject))
{
BUGManager.Instance.LogStackOverflowBug(this.transform);
StartCoroutine(GameManager.Instance.ReStartGame());
return;
}

View File

@@ -6,14 +6,28 @@ using UnityEngine.Events;
namespace Script.Gameplay.Global
{
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;
}
}
public struct StackOverflowBUGLog
{
public Transform TargetTransform;
public TransformSnapshot TargetSnapshot;
public int BeTriggerCycle; // 触发时的游戏循环次数
public StackOverflowBUGLog(Transform targetTransform, int beTriggerCycle)
{
TargetTransform = targetTransform;
TargetSnapshot = new TransformSnapshot(targetTransform);
BeTriggerCycle = beTriggerCycle;
}
}
@@ -24,57 +38,60 @@ namespace Script.Gameplay.Global
[Header("天核区域检测设置")] [SerializeField] private Vector3 AreaCenter = Vector3.zero;
[SerializeField] private Vector3 AreaSize = new Vector3(50, 50, 50);
public UnityEvent OnBUGHappenedInArea;
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;
}
OnBugHappenedInArea.AddListener(() => { Debug.Log("天核区域内检测到BUG立方体"); });
public void LogStackOverflowBUG(Transform targetTransform)
GameManager.Instance.OnGameStart += GenerateBugCubes;
}
public void LogStackOverflowBug(Transform targetTransform)
{
int beTriggerCycle = GameDataManager.Instance.TotalLoopCount;
stackOverflowBugLogs.Add(new StackOverflowBUGLog(targetTransform, beTriggerCycle));
StartCoroutine(GameManager.Instance.ReStartGame());
}
public void GenerateBUGCubes()
public void GenerateBugCubes()
{
foreach (var bugCube in bugCubes)
{
Destroy(bugCube);
}
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立方体
if (currentCycle - log.BeTriggerCycle >= 0 && currentCycle - log.BeTriggerCycle < 2)
{
GameObject go = Instantiate(bugCubePrefab, log.TargetSnapshot.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();
OnBugHappenedInArea?.Invoke();
break;
}
}
}
// 可视化天核区域
private void OnDrawGizmosSelected()
{

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 7d84f38f95b036341be84c3534ef9627
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}

View File

@@ -2423,7 +2423,7 @@
"m_Title": "Timer",
"m_Position": {
"x": -2373.142822265625,
"y": 1482.857177734375
"y": 1482.8570556640625
}
}
@@ -2689,7 +2689,7 @@
"m_Title": "Noise",
"m_Position": {
"x": -3592.0,
"y": 620.0
"y": 619.9999389648438
}
}