feat(BUGCube):实现BUG位置生成异常方块
This commit is contained in:
@@ -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}的连接线的配置错误,生成失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,6 +149,7 @@ namespace Script.Gameplay.Facility
|
||||
// 利用DFS检测是否存在连接环
|
||||
if (DfsCheckConnectionRing(this.gameObject))
|
||||
{
|
||||
BUGManager.Instance.LogStackOverflowBug(this.transform);
|
||||
StartCoroutine(GameManager.Instance.ReStartGame());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user