Unity 2018 Artificial Intelligence Cookbook(Second Edition)
上QQ阅读APP看书,第一时间看更新

There's more...

We called the BuildPath function, but we haven't implemented it yet. It is important to note that this function is called by almost every other path-finding algorithm in this chapter; that's why it's not part of the main recipe.

This is the code for the BuildPath method:

private List<Vertex> BuildPath(int srcId, int dstId, ref int[] prevList) 
{ 
    List<Vertex> path = new List<Vertex>(); 
    int prev = dstId; 
    do 
    { 
        path.Add(vertices[prev]); 
        prev = prevList[prev]; 
    } while (prev != srcId); 
    return path; 
}