@sssunny
2024-04-03T03:54:31.000000Z
字数 1279
阅读 135
AStarPathFinding
TiledMap
AStarPathFinding 官网
AStarPathFinding 文档
目前方向:
- 方案一:修改 GridGraph 生成
- 方案二:tiledMap 数据格式生成Prefab,再生成A*网格数据(暂不启用,可以研究)
GridGraph.ScanInternal();
// 关键代码
for (int z = 0; z < depth; z++) {
// Yield with a progress value at most every N nodes
if (progressCounter >= YieldEveryNNodes) {
progressCounter = 0;
yield return new Progress(Mathf.Lerp(0.1f, 0.7f, z/(float)depth), "Calculating positions");
}
progressCounter += width;
for (int x = 0; x < width; x++) {
// Updates the position of the node 更新节点的位置
// and a bunch of other things 还有其他一些事情
RecalculateCell(x, z);
// Apply texture data if necessary
textureData.Apply(nodes[z*width + x], x, z);
}
}
// Bounds of the collider the last time the graphs were updated
Bounds prevBounds;
var guo = new GraphUpdateObject(prevBounds);
AstarPath.active.UpdateGraphs(guo);
private NavmeshBase _recastGraph;
_recastGraph = AStar.data.recastGraph;
// 将包含最接近的节点和该节点曲面上最接近的点
// 如果要检查所有图形,则可以使用 AstarPath.GetNearest
// AStar.GetNearest(pos);
pos = _recastGraph.GetNearest(pos).position;
// 查找包含位置的第一个节点。
// “Contains”定义为从上方观察时位于三角形节点内部的位置。
// 在多层环境的情况下,将返回包含该点的最近节点。
// 如果没有包含该点的节点,则返回null。这起到了快速
// 检查“这一点是否在导航网格上”。
var node = _recastGraph.PointOnNavmesh(pos, NNConstraint.None);