本文整理汇总了C#中PathNode.toPath方法的典型用法代码示例。如果您正苦于以下问题:C# PathNode.toPath方法的具体用法?C# PathNode.toPath怎么用?C# PathNode.toPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PathNode
的用法示例。
在下文中一共展示了PathNode.toPath方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: findPath
public Vec2int[] findPath(int startX, int startY, int goalX, int goalY, int restrictCost, bool ignorecollision)
{
if((!ignorecollision && (!tiles[startX, startY].traversable || !tiles[goalX, goalY].traversable)) || (startX == goalX && startY == goalY)) return null;
List<PathNode> reachable = new List<PathNode>();
List<PathNode> visited = new List<PathNode>();
reachable.Add(new PathNode(startX, startY));
while(reachable.Count != 0){
PathNode cheapest = new PathNode();
float fcost = -1;
foreach(PathNode node in reachable){
if(fcost == -1 || node.f <= fcost){
fcost = node.f;
cheapest = node;
}
}
if(cheapest.g >= restrictCost){
return null;
}
visited.Add(cheapest);
reachable.Remove(cheapest);
foreach(Hexagon hex in tiles[cheapest.x, cheapest.y].getAdjacent()){
bool gotVisited = false;
foreach(PathNode vNode in visited){
if(hex.gridPos.x == vNode.x && hex.gridPos.y == vNode.y){
gotVisited = true;
break;
}
}
if((hex.traversable || ignorecollision) && !gotVisited){
bool isReachable= false;
foreach(PathNode rNode in reachable){
if(hex.gridPos.x == rNode.x && hex.gridPos.y == rNode.y){
isReachable = true;
rNode.tryAlternative(cheapest);
break;
}
}
if(!isReachable){
PathNode nNode = new PathNode(hex.gridPos.x, hex.gridPos.y, cheapest, goalX, goalY);
if(hex.gridPos.x == goalX && hex.gridPos.y == goalY) return nNode.toPath();
reachable.Add(nNode);
}
}
}
}
return null;
}