从关卡几何体创建导航网格的过程称为导航网格烘焙 (NavMesh Baking)。该过程收集所有标记为 Navigation Static 的游戏对象的渲染网格和地形,然后处理它们以创建近似于关卡的可行走表面的导航网格。
在 Unity 中,导航网格生成方式是在 Navigation 窗口(菜单:__Window__ > AI > __Navigation__)中进行处理的。
为场景构建导航网格可以通过 4 个快速步骤完成:
每当 Navigation 窗口打开且可见时,生成的导航网格便会在场景中显示为底层关卡几何体上的蓝色覆盖层。
您可能已经在上面的图片中注意到,生成的导航网格中的可行走区域显示为缩小状态。导航网格表示代理中心可进行移动的区域。从概念上讲,无论将代理视为缩小的导航网格上的点还是全尺寸的导航网格上的圆都无关紧要,因为这两者是等效的。但是,解释为点有助于提高运行时效率,并可让设计人员立即看到代理是否可以挤过间隙而不用担心代理半径问题。
另外要记住的是导航网格是可行走表面的近似形状。例如,在楼梯中就能看出这一点:楼梯表示为平坦表面,但原始表面是有台阶的。这种表示方式是为了使导航网格数据大小保持较小。这种近似表示方式的副作用是,有时您会希望在关卡几何体中留出一些额外的空间,让代理能够通过一个狭窄位置。
烘焙完成后,您将在一个与导航网格所属场景同名的文件夹中找到导航网格资源文件。例如,如果在 Assets 文件夹中有一个名为 First Level 的场景,则导航网格将位于 Assets > First Level > NavMesh.asset。
除了如上所述在 Navigation 窗口中将对象标记为 Navigation Static 之外,还可以使用 Inspector 顶部的 Static 菜单。如果刚好没有打开 Navigation 窗口,这会很方便。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.