feat(SignalCycle):实现提前检测信号循环,触发重启
This commit is contained in:
@@ -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}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -233,6 +233,7 @@ MonoBehaviour:
|
||||
needSignalCount: 1
|
||||
currentSignalCount: 0
|
||||
componentName:
|
||||
isEnableSendSignal: 1
|
||||
startPositionObject: {fileID: 3154147150921727065}
|
||||
targetPositionObject: {fileID: 2516956888757501734}
|
||||
moveSpeed: 2
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -173,7 +173,7 @@ MonoBehaviour:
|
||||
needSignalCount: 1
|
||||
currentSignalCount: 0
|
||||
componentName:
|
||||
isEnableSendSignal: 0
|
||||
isEnableSendSignal: 1
|
||||
destinationPoint: {fileID: 8009085288281141996}
|
||||
playerTag: Player
|
||||
transportDelay: 0.1
|
||||
|
||||
@@ -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
|
||||
/// <param name="sender">让此物体触发发送的来源者</param>
|
||||
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<IConnectable>();
|
||||
if (rootConnect == null) return false;
|
||||
|
||||
var visited = new HashSet<GameObject>();
|
||||
|
||||
// 内部递归 DFS,parent 用于避免把返回到父节点误判为环
|
||||
bool Dfs(GameObject current, GameObject parent)
|
||||
{
|
||||
if (current == null) return false;
|
||||
visited.Add(current);
|
||||
|
||||
var conn = current.GetComponent<IConnectable>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,31 +11,5 @@ namespace Script.Gameplay.Interface
|
||||
GameObject GetGameObject(); // 获取连接点物体
|
||||
string GetConnectableName(); // 获取连接点名称
|
||||
public List<ConnectionLine> ConnectionLines { get; set; }
|
||||
|
||||
// public static List<GameObject> GetConnectedGameObjects(GameObject sender)
|
||||
// {
|
||||
// IConnectable connectable = sender.GetComponent<IConnectable>();
|
||||
// List<GameObject> connectedObjects = new List<GameObject>();
|
||||
// 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;
|
||||
// }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user