diff --git a/Assets/Prefab/Gameplay/Console.prefab b/Assets/Prefab/Gameplay/Console.prefab index 5889419..d951c25 100644 --- a/Assets/Prefab/Gameplay/Console.prefab +++ b/Assets/Prefab/Gameplay/Console.prefab @@ -221,9 +221,11 @@ MonoBehaviour: isEnableInteract: 1 isEnableEdit: 1 isEnableConnect: 1 - componentName: - needSignalCount: 2 isOpenInEditor: 1 + needSignalCount: 2 + currentSignalCount: 0 + componentName: + isEnableSendSignal: 1 sendSignalMode: 1 controlTarget: - {fileID: 0} diff --git a/Assets/Prefab/Gameplay/Emitter.prefab b/Assets/Prefab/Gameplay/Emitter.prefab index b187f35..191cc2d 100644 --- a/Assets/Prefab/Gameplay/Emitter.prefab +++ b/Assets/Prefab/Gameplay/Emitter.prefab @@ -169,9 +169,12 @@ MonoBehaviour: isEnableInteract: 1 isEnableEdit: 1 isEnableConnect: 1 - componentName: - needSignalCount: 1 isOpenInEditor: 1 + needSignalCount: 1 + currentSignalCount: 0 + componentName: + isEnableSendSignal: 1 + isEmittingOnStart: 0 prefabToEmit: {fileID: 7979385610396712053, guid: 9fc63211af583b946b1f381e4bf38ddf, type: 3} emitPoint: {fileID: 119873216418816890} @@ -179,6 +182,11 @@ MonoBehaviour: emitForce: 10 emitInterval: 1 destroyDelay: 5 + overridePrefabScale: 0 + fixedScale: {x: 1, y: 1, z: 1} + randomizeScale: 0 + minScale: {x: 1, y: 1, z: 1} + maxScale: {x: 1, y: 1, z: 1} --- !u!114 &8359041934045797068 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Prefab/Gameplay/MovingPlatform.prefab b/Assets/Prefab/Gameplay/MovingPlatform.prefab index aed8920..3889793 100644 --- a/Assets/Prefab/Gameplay/MovingPlatform.prefab +++ b/Assets/Prefab/Gameplay/MovingPlatform.prefab @@ -233,6 +233,7 @@ MonoBehaviour: needSignalCount: 1 currentSignalCount: 0 componentName: + isEnableSendSignal: 1 startPositionObject: {fileID: 3154147150921727065} targetPositionObject: {fileID: 2516956888757501734} moveSpeed: 2 diff --git a/Assets/Prefab/Gameplay/NumberSlot.prefab b/Assets/Prefab/Gameplay/NumberSlot.prefab index 424b5b8..32869ad 100644 --- a/Assets/Prefab/Gameplay/NumberSlot.prefab +++ b/Assets/Prefab/Gameplay/NumberSlot.prefab @@ -137,9 +137,11 @@ MonoBehaviour: isEnableInteract: 1 isEnableEdit: 1 isEnableConnect: 1 - componentName: - needSignalCount: 1 isOpenInEditor: 1 + needSignalCount: 1 + currentSignalCount: 0 + componentName: + isEnableSendSignal: 1 currentNumber: 0 correctNumber: 1 --- !u!114 &1413885433821236986 diff --git a/Assets/Prefab/Gameplay/Transport.prefab b/Assets/Prefab/Gameplay/Transport.prefab index 1953f76..788579e 100644 --- a/Assets/Prefab/Gameplay/Transport.prefab +++ b/Assets/Prefab/Gameplay/Transport.prefab @@ -173,7 +173,7 @@ MonoBehaviour: needSignalCount: 1 currentSignalCount: 0 componentName: - isEnableSendSignal: 0 + isEnableSendSignal: 1 destinationPoint: {fileID: 8009085288281141996} playerTag: Player transportDelay: 0.1 diff --git a/Assets/Script/Gameplay/Facility/BaseFacilityController.cs b/Assets/Script/Gameplay/Facility/BaseFacilityController.cs index a5ec724..8c5c07c 100644 --- a/Assets/Script/Gameplay/Facility/BaseFacilityController.cs +++ b/Assets/Script/Gameplay/Facility/BaseFacilityController.cs @@ -3,6 +3,7 @@ using Script.Gameplay.Connect; using Script.Gameplay.Global; using Script.Gameplay.Interface; using UnityEngine; +using UnityEngine.Experimental.GlobalIllumination; namespace Script.Gameplay.Facility { @@ -112,7 +113,7 @@ namespace Script.Gameplay.Facility { SendSignal(active, sender); } - + if (active) { CurrentNeedSignalCount++; @@ -142,15 +143,15 @@ namespace Script.Gameplay.Facility /// 让此物体触发发送的来源者 public virtual void SendSignal(bool active, GameObject sender) { - if(!IsEnableSendSignal) return; + if (!IsEnableSendSignal) return; if (ConnectionLines != null) { - // if (ISignalSender.IsSendToSignalSender(this.gameObject)) - // { - // // 防止信号回传给发送者自己 - // BUGManager.Instance.LogStackOverflowBUG(this.transform); - // return; - // } + // 利用DFS检测是否存在连接环 + if (DfsCheckConnectionRing(this.gameObject)) + { + StartCoroutine(GameManager.Instance.ReStartGame()); + return; + } foreach (var line in ConnectionLines) { @@ -159,9 +160,63 @@ namespace Script.Gameplay.Facility { continue; } + line.OnSignalReceived(active, this.gameObject); } } } + + public static bool DfsCheckConnectionRing(GameObject root) + { + if (root == null) return false; + + var rootConnect = root.GetComponent(); + if (rootConnect == null) return false; + + var visited = new HashSet(); + + // 内部递归 DFS,parent 用于避免把返回到父节点误判为环 + bool Dfs(GameObject current, GameObject parent) + { + if (current == null) return false; + visited.Add(current); + + var conn = current.GetComponent(); + if (conn == null) return false; + + foreach (var line in conn.ConnectionLines) + { + if (line == null) continue; + + GameObject a = line.PointA?.GetGameObject(); + GameObject b = line.PointB?.GetGameObject(); + + GameObject neighbor = null; + if (a == current) neighbor = b; + else if (b == current) neighbor = a; + else continue; // 如果这条线并未连接到 current,跳过 + + if (neighbor == null) continue; + + // 如果邻居是父节点,跳过(因为这是无向边回到父) + if (neighbor == parent) continue; + + // 已访问到其他非父节点,说明存在环 + if (visited.Contains(neighbor)) + { + return true; + } + + if (Dfs(neighbor, current)) + { + return true; + } + } + + return false; + } + + return Dfs(root, null); + } } } \ No newline at end of file diff --git a/Assets/Script/Gameplay/Interface/IConnectable.cs b/Assets/Script/Gameplay/Interface/IConnectable.cs index 2b96956..1a5ddd9 100644 --- a/Assets/Script/Gameplay/Interface/IConnectable.cs +++ b/Assets/Script/Gameplay/Interface/IConnectable.cs @@ -11,31 +11,5 @@ namespace Script.Gameplay.Interface GameObject GetGameObject(); // 获取连接点物体 string GetConnectableName(); // 获取连接点名称 public List ConnectionLines { get; set; } - - // public static List GetConnectedGameObjects(GameObject sender) - // { - // IConnectable connectable = sender.GetComponent(); - // List connectedObjects = new List(); - // if (connectable != null) - // { - // foreach (var target in connectable.ConnectionLines) - // { - // if (target != null && target.PointA != null && target.PointB != null) - // { - // // 排除掉AB点中与sender相同的点 - // if (target.PointA.GetGameObject() != sender) - // { - // connectedObjects.Add(target.PointA.GetGameObject()); - // } - // - // if (target.PointB.GetGameObject() != sender) - // { - // connectedObjects.Add(target.PointB.GetGameObject()); - // } - // } - // } - // } - // return connectedObjects; - // } } } \ No newline at end of file