private static bool TraverseRecursively(Shape shape, List <ChainItem> chain) { _traversedShapes.Add(shape); bool chainItemHasConnector = false; ChainItem chainItem = new ChainItem(); chainItem.Shape = shape; chainItem.TargetDirection = shape.CurrentDirection; chain.Add(chainItem); var connector = FindConnectorWithConnection(shape); if (connector != null && shape.HasConnection(connector.CurrentDirection)) { //Debug.LogWarning(connector.name); chainItemHasConnector = true; _unTraversedConnectors.Remove(connector); } var neighbors = NodesGrid.FindConnectedNeighborShapes(shape); bool hasFirstChain = false; foreach (var neighbor in neighbors) { if (!_traversedShapes.Contains(neighbor)) { List <ChainItem> targetChain = chain; if (hasFirstChain) { targetChain = chainItem.childChain; } bool nextChainItemHasConnector = TraverseRecursively(neighbor, targetChain); chainItemHasConnector |= nextChainItemHasConnector; hasFirstChain = true; } } //если текущая нода не соединена с коннектором и дочерние ответвления тоже не соединены с коннектором, то удалить данный узел. if (!chainItemHasConnector) { //chainItem.Shape.name += "_RemovedChainItem"; chain.Remove(chainItem); } return(chainItemHasConnector); }
private void CheckConnectRecursively(Shape shape) { _traversedShapes.Add(shape); var connector = FindConnectorWithConnection(shape); if (connector != null && shape.HasConnection(connector.CurrentDirection)) { _unConnectedConnectors.Remove(connector); } var neighbors = NodesGrid.FindConnectedNeighborShapes(shape); foreach (var neighbor in neighbors) { if (!_traversedShapes.Contains(neighbor)) { CheckConnectRecursively(neighbor); } } }