示例#1
0
    public Stack <Vector3Int> Algorithm(Vector3Int start, Vector3Int goal, NodeGrid grid)
    {
        _CurrentNode = grid.GetNode(start);

        _OpenList   = new HashSet <Node>();
        _ClosedList = new HashSet <Node>();

        _OpenList.Add(_CurrentNode);

        Stack <Vector3Int> path = null;

        while (_OpenList.Count > 0 && path == null)
        {
            List <Node> neighbors = grid.FindNeighbors(_CurrentNode.Position);

            ExamineNeighbors(neighbors, _CurrentNode, goal, grid);

            UpdateCurrentTile(ref _CurrentNode);

            path = GeneratePath(_CurrentNode, start, goal);
        }

        AStarDebug.Instance?.CreateTiles(_OpenList, _ClosedList, grid, start, goal, path);

        return(path);
    }