private void TraceBackpath(CellForAstar successorCell) { CellForAstar currentNode = successorCell; while (currentNode != null) { CurrentPath.Add(currentNode.Cell); currentNode = currentNode.Parent; } CurrentPath.Reverse(); }
public Vector3Int[] GetPath(Vector3 GoalFloat, Vector3 StartCellFloat, float ArrowAvoidance) { Vector3Int Goal = TileMap.WorldToCell(GoalFloat); Vector3Int startCell = TileMap.WorldToCell(StartCellFloat); if (GameRule.get.NearBoomerang(startCell, ArrowAvoidance)) { ArrowAvoidance = 0.0f; } AlgoritmOpenList.Clear(); CloseList.Clear(); CurrentPath.Clear(); AlgoritmOpenList.Add(new CellForAstar(startCell)); while (AlgoritmOpenList.Count > 0) { CellForAstar currentCell = AlgoritmOpenList[0]; AlgoritmOpenList.RemoveAt(0); foreach (Vector3Int Node in IterateThroughNeighbors(currentCell.Cell)) { if (!IsWalkable(Node, ArrowAvoidance)) { continue; } if (CloseList.Contains(Node)) { continue; } CellForAstar successorCell = new CellForAstar(Node); successorCell.Parent = currentCell; if (Node == Goal) { TraceBackpath(successorCell); break; } if (AlgoritmOpenList.Find(element => element.Cell == Node) == null) { AlgoritmOpenList.Add(successorCell); } } if (CurrentPath.Count > 0) { break; } CloseList.Add(currentCell.Cell); } return(CurrentPath.ToArray()); }