导航网格表面 (NavMesh Surface) 组件表示特定导航网格代理 (NavMesh Agent) 类型的可行走区域,并定义应构建导航网格的场景部分。
导航网格表面组件不在 Unity 标准安装中;有关如何访问该组件的信息,请参阅高级导航网格构建组件的文档。
要使用导航网格表面组件,请导航至 GameObject > AI > NavMesh Surface。此操作会创建一个附加了导航网格表面组件的空游戏对象。一个场景可以包含多个导航网格表面。
您可以将导航网格表面组件添加到任何游戏对象。当您想要使用游戏对象管控层级视图来定义哪些游戏对象对导航网格有影响时,这非常有用。
属性 | 功能 |
---|---|
Agent Type | 使用导航网格表面的导航网格代理类型。用于烘焙设置以及在寻路期间将导航网格代理与正确的表面相匹配。 - Humanoid - Ogre |
Collect Objects | 定义要用于烘焙的游戏对象。 - All – 使用所有激活的游戏对象(这是默认选项)。 - Volume – 使用与包围体重叠的所有激活状态游戏对象。 - Children – 使用所有充当导航网格表面组件的子项的激活状态游戏对象。 |
Include Layers | 定义要将哪些层上的游戏对象包含在烘焙中。除了 Collect Objects 之外,此属性还允许从烘焙中进一步排除特定的游戏对象(例如,效果或动画角色)。 此属性在默认情况下设置为 Everything__,但您可以单独对以下选项进行开关切换(由选中标记表示): - Nothing__(自动取消勾选所有其他选项,将它们关闭) - Everything__(自动勾选所有其他选项,将它们打开) - Default__ - TransparentFX - Ignore Raycast - Water - UI |
Use Geometry | 选择用于烘焙的几何体。 - Render Meshes – 使用渲染网格和地形中的几何体。 – Physics Colliders – 使用碰撞体和地形中的几何体。此选项与 Render Meshes 选项相比,代理可以移动到更接近环境物理边界的边缘。 |
使用导航网格表面组件的主要设置可以大范围过滤输入几何体。使用导航网格修改器 (NavMesh Modifier) 组件可以微调 Unity 针对每个游戏对象处理输入几何体的方式。
烘焙过程会自动排除具有导航网格代理 (NavMesh Agent) 或导航网格障碍物 (NavMesh Obstacle) 的游戏对象。这些游戏对象是导航网格的动态用户,因此不参与导航网格构建。
在 Advanced 设置部分可自定义以下附加参数:
属性 | 功能 |
---|---|
Default Area | 定义构建导航网格时生成的区域类型。 - Walkable__(这是默认选项) - Not Walkable - Jump__ 使用导航网格修改器组件可以更详细地修改区域类型。 |
Override Voxel Size | 控制 Unity 处理导航网格烘焙的输入几何体的准确程度(这是速度和准确度之间的权衡)。选中复选框可启用该属性。默认情况下会取消选中该复选框(禁用)。 每个代理半径 3 个体素(每个直径 6 个)允许捕获狭窄的通道(例如门),同时保持快速烘焙。对于大型开放区域,每个半径使用 1 或 2 个体素可加快烘焙速度。室内的密集点更适合较小的体素,例如每个半径 4 到 6 个体素。每个半径超过 8 个体素通常不会进一步带来好处。 |
Override Tile Size | 为了使烘焙过程并行执行且提高内存效率,场景将分区进行烘焙。导航网格上可见的白线是区块边界。 默认区块大小为 256 个体素,这种大小在内存使用和导航网格碎片之间提供了良好的折衷。 要更改此默认区块大小,请选中此复选框,然后在 Tile Size 字段中输入您希望 Tile Size 包含的体素数。 区块越小,导航网格就越碎片化。这种情况下有时会导致非最佳路径。导航网格雕刻也基于区块进行。如果有很多障碍物,通常可以通过减小区块大小(例如大约 64 到 128 个体素)来加速雕刻。如果您计划在运行时烘焙导航网格,请使用较小的区块大小以使最高内存使用率处于较低水平。 |
Build Height Mesh | 不支持。 |
使用 Debug Visualization 部分中的设置可诊断导航网格构建过程中遇到的任何问题。不同的复选框显示了导航网格构建过程的每个步骤,包括输入场景体素化 (Input Geometry)、区域分割 (Regions)、轮廓生成 (Contours) 和导航网格多边形 (Polygon Meshes)。
2017–09–14 页面已发布
5.6 中的新功能
在 2017.2 版中添加了新的高级调试可视化 (Debug Visualization) NewIn20172
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.