Version: 2022.3
导航系统的内部工作原理
高级导航网格烘焙设置

Building a NavMesh

The process of creating a NavMesh from the level geometry is called NavMesh Baking. The process collects the Render Meshes and Terrains of all Game Objects which are marked as Navigation Static, and then processes them to create a navigation mesh that approximates the walkable surfaces of the level.

In Unity, NavMesh generation is handled from the Navigation window (menu: Window > AI > Navigation (Obsolete)).

为场景构建导航网格可以通过 4 个快速步骤完成:

  1. 选择应影响导航的场景几何体:可行走表面和障碍物。
  2. 选中 Navigation Static 复选框以便在导航网格烘焙过程中包括所选对象。
  3. 调整烘焙设置以匹配代理大小。
    • Agent Radius 定义代理中心与墙壁或窗台的接近程度。
    • Agent Height 定义代理可以达到的空间有多低。
    • Max Slope 定义代理走上坡道的陡峭程度。
    • Step Height 定义代理可以踏上的障碍物的高度。
  4. 单击 Bake 以构建导航网格。

每当 Navigation 窗口打开且可见时,生成的导航网格便会在场景中显示为底层关卡几何体上的蓝色覆盖层。

您可能已经在上面的图片中注意到,生成的导航网格中的可行走区域显示为缩小状态。导航网格表示代理中心可进行移动的区域。从概念上讲,无论将代理视为缩小的导航网格上的点还是全尺寸的导航网格上的圆都无关紧要,因为这两者是等效的。但是,解释为点有助于提高运行时效率,并可让设计人员立即看到代理是否可以挤过间隙而不用担心代理半径问题。

Another thing to keep in mind is that the NavMesh is an approximation of the walkable surface. This can be seen for example in the stairs which are represented as a flat surface, while the source surface has steps. This is done in order to keep the NavMesh data size small. The side effect of the approximation is that sometimes you will need to have a little extra space in your level geometry to allow the agent to pass through any tight spots.

烘焙完成后,您将在一个与导航网格所属场景同名的文件夹中找到导航网格资源文件。例如,如果在 Assets 文件夹中有一个名为 First Level 的场景,则导航网格将位于 Assets > First Level > NavMesh.asset

Additional resources

导航系统的内部工作原理
高级导航网格烘焙设置