Files
godot-docs-l10n/classes/zh_CN/class_navigationpolygon.rst

643 lines
34 KiB
ReStructuredText

:github_url: hide
.. DO NOT EDIT THIS FILE!!!
.. Generated automatically from Godot engine sources.
.. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
.. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/NavigationPolygon.xml.
.. _class_NavigationPolygon:
NavigationPolygon
=================
**实验性:** This class may be changed or removed in future versions.
**继承:** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
2D 导航网格,描述用于寻路的可穿越表面。
.. rst-class:: classref-introduction-group
描述
----
导航网格可以通过在 :ref:`NavigationServer2D<class_NavigationServer2D>` 的帮助下烘焙它来创建,也可以通过手动添加顶点和凸多边形索引数组来创建。
要烘焙导航网格,至少需要添加一个轮廓来定义烘焙区域的外部边界。
.. tabs::
.. code-tab:: gdscript
var new_navigation_mesh = NavigationPolygon.new()
var bounding_outline = PackedVector2Array([Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)])
new_navigation_mesh.add_outline(bounding_outline)
NavigationServer2D.bake_from_source_geometry_data(new_navigation_mesh, NavigationMeshSourceGeometryData2D.new());
$NavigationRegion2D.navigation_polygon = new_navigation_mesh
.. code-tab:: csharp
var newNavigationMesh = new NavigationPolygon();
var boundingOutline = new Vector2[] { new Vector2(0, 0), new Vector2(0, 50), new Vector2(50, 50), new Vector2(50, 0) };
newNavigationMesh.AddOutline(boundingOutline);
NavigationServer2D.BakeFromSourceGeometryData(newNavigationMesh, new NavigationMeshSourceGeometryData2D());
GetNode<NavigationRegion2D>("NavigationRegion2D").NavigationPolygon = newNavigationMesh;
手动添加顶点和多边形索引。
.. tabs::
.. code-tab:: gdscript
var new_navigation_mesh = NavigationPolygon.new()
var new_vertices = PackedVector2Array([Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)])
new_navigation_mesh.vertices = new_vertices
var new_polygon_indices = PackedInt32Array([0, 1, 2, 3])
new_navigation_mesh.add_polygon(new_polygon_indices)
$NavigationRegion2D.navigation_polygon = new_navigation_mesh
.. code-tab:: csharp
var newNavigationMesh = new NavigationPolygon();
var newVertices = new Vector2[] { new Vector2(0, 0), new Vector2(0, 50), new Vector2(50, 50), new Vector2(50, 0) };
newNavigationMesh.Vertices = newVertices;
var newPolygonIndices = new int[] { 0, 1, 2, 3 };
newNavigationMesh.AddPolygon(newPolygonIndices);
GetNode<NavigationRegion2D>("NavigationRegion2D").NavigationPolygon = newNavigationMesh;
.. rst-class:: classref-introduction-group
教程
----
- :doc:`使用 NavigationMesh <../tutorials/navigation/navigation_using_navigationmeshes>`
- `2D 导航多边形演示 <https://godotengine.org/asset-library/asset/2722>`__
.. rst-class:: classref-reftable-group
属性
----
.. table::
:widths: auto
+----------------------------------------------------------------------+------------------------------------------------------------------------------------------------+-------------------------------------------------+
| :ref:`float<class_float>` | :ref:`agent_radius<class_NavigationPolygon_property_agent_radius>` | ``10.0`` |
+----------------------------------------------------------------------+------------------------------------------------------------------------------------------------+-------------------------------------------------+
| :ref:`Rect2<class_Rect2>` | :ref:`baking_rect<class_NavigationPolygon_property_baking_rect>` | ``Rect2(0, 0, 0, 0)`` |
+----------------------------------------------------------------------+------------------------------------------------------------------------------------------------+-------------------------------------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`baking_rect_offset<class_NavigationPolygon_property_baking_rect_offset>` | ``Vector2(0, 0)`` |
+----------------------------------------------------------------------+------------------------------------------------------------------------------------------------+-------------------------------------------------+
| :ref:`float<class_float>` | :ref:`border_size<class_NavigationPolygon_property_border_size>` | ``0.0`` |
+----------------------------------------------------------------------+------------------------------------------------------------------------------------------------+-------------------------------------------------+
| :ref:`float<class_float>` | :ref:`cell_size<class_NavigationPolygon_property_cell_size>` | ``1.0`` |
+----------------------------------------------------------------------+------------------------------------------------------------------------------------------------+-------------------------------------------------+
| :ref:`int<class_int>` | :ref:`parsed_collision_mask<class_NavigationPolygon_property_parsed_collision_mask>` | ``4294967295`` |
+----------------------------------------------------------------------+------------------------------------------------------------------------------------------------+-------------------------------------------------+
| :ref:`ParsedGeometryType<enum_NavigationPolygon_ParsedGeometryType>` | :ref:`parsed_geometry_type<class_NavigationPolygon_property_parsed_geometry_type>` | ``2`` |
+----------------------------------------------------------------------+------------------------------------------------------------------------------------------------+-------------------------------------------------+
| :ref:`StringName<class_StringName>` | :ref:`source_geometry_group_name<class_NavigationPolygon_property_source_geometry_group_name>` | ``&"navigation_polygon_source_geometry_group"`` |
+----------------------------------------------------------------------+------------------------------------------------------------------------------------------------+-------------------------------------------------+
| :ref:`SourceGeometryMode<enum_NavigationPolygon_SourceGeometryMode>` | :ref:`source_geometry_mode<class_NavigationPolygon_property_source_geometry_mode>` | ``0`` |
+----------------------------------------------------------------------+------------------------------------------------------------------------------------------------+-------------------------------------------------+
.. rst-class:: classref-reftable-group
方法
----
.. table::
:widths: auto
+-----------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`add_outline<class_NavigationPolygon_method_add_outline>`\ (\ outline\: :ref:`PackedVector2Array<class_PackedVector2Array>`\ ) |
+-----------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`add_outline_at_index<class_NavigationPolygon_method_add_outline_at_index>`\ (\ outline\: :ref:`PackedVector2Array<class_PackedVector2Array>`, index\: :ref:`int<class_int>`\ ) |
+-----------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`add_polygon<class_NavigationPolygon_method_add_polygon>`\ (\ polygon\: :ref:`PackedInt32Array<class_PackedInt32Array>`\ ) |
+-----------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`clear<class_NavigationPolygon_method_clear>`\ (\ ) |
+-----------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`clear_outlines<class_NavigationPolygon_method_clear_outlines>`\ (\ ) |
+-----------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`clear_polygons<class_NavigationPolygon_method_clear_polygons>`\ (\ ) |
+-----------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`NavigationMesh<class_NavigationMesh>` | :ref:`get_navigation_mesh<class_NavigationPolygon_method_get_navigation_mesh>`\ (\ ) |
+-----------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`PackedVector2Array<class_PackedVector2Array>` | :ref:`get_outline<class_NavigationPolygon_method_get_outline>`\ (\ idx\: :ref:`int<class_int>`\ ) |const| |
+-----------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`get_outline_count<class_NavigationPolygon_method_get_outline_count>`\ (\ ) |const| |
+-----------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>` | :ref:`get_parsed_collision_mask_value<class_NavigationPolygon_method_get_parsed_collision_mask_value>`\ (\ layer_number\: :ref:`int<class_int>`\ ) |const| |
+-----------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`PackedInt32Array<class_PackedInt32Array>` | :ref:`get_polygon<class_NavigationPolygon_method_get_polygon>`\ (\ idx\: :ref:`int<class_int>`\ ) |
+-----------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`get_polygon_count<class_NavigationPolygon_method_get_polygon_count>`\ (\ ) |const| |
+-----------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`PackedVector2Array<class_PackedVector2Array>` | :ref:`get_vertices<class_NavigationPolygon_method_get_vertices>`\ (\ ) |const| |
+-----------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`make_polygons_from_outlines<class_NavigationPolygon_method_make_polygons_from_outlines>`\ (\ ) |
+-----------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`remove_outline<class_NavigationPolygon_method_remove_outline>`\ (\ idx\: :ref:`int<class_int>`\ ) |
+-----------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`set_outline<class_NavigationPolygon_method_set_outline>`\ (\ idx\: :ref:`int<class_int>`, outline\: :ref:`PackedVector2Array<class_PackedVector2Array>`\ ) |
+-----------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`set_parsed_collision_mask_value<class_NavigationPolygon_method_set_parsed_collision_mask_value>`\ (\ layer_number\: :ref:`int<class_int>`, value\: :ref:`bool<class_bool>`\ ) |
+-----------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`set_vertices<class_NavigationPolygon_method_set_vertices>`\ (\ vertices\: :ref:`PackedVector2Array<class_PackedVector2Array>`\ ) |
+-----------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
枚举
----
.. _enum_NavigationPolygon_ParsedGeometryType:
.. rst-class:: classref-enumeration
enum **ParsedGeometryType**: :ref:`🔗<enum_NavigationPolygon_ParsedGeometryType>`
.. _class_NavigationPolygon_constant_PARSED_GEOMETRY_MESH_INSTANCES:
.. rst-class:: classref-enumeration-constant
:ref:`ParsedGeometryType<enum_NavigationPolygon_ParsedGeometryType>` **PARSED_GEOMETRY_MESH_INSTANCES** = ``0``
将网格实例解析为障碍几何体。这包括 :ref:`Polygon2D<class_Polygon2D>`\ 、\ :ref:`MeshInstance2D<class_MeshInstance2D>`\ 、\ :ref:`MultiMeshInstance2D<class_MultiMeshInstance2D>`:ref:`TileMap<class_TileMap>` 节点。
仅当网格使用 2D 顶点表面格式时才会对其进行解析。
.. _class_NavigationPolygon_constant_PARSED_GEOMETRY_STATIC_COLLIDERS:
.. rst-class:: classref-enumeration-constant
:ref:`ParsedGeometryType<enum_NavigationPolygon_ParsedGeometryType>` **PARSED_GEOMETRY_STATIC_COLLIDERS** = ``1``
:ref:`StaticBody2D<class_StaticBody2D>`:ref:`TileMap<class_TileMap>` 碰撞器解析为障碍几何体。碰撞器应在由 :ref:`parsed_collision_mask<class_NavigationPolygon_property_parsed_collision_mask>` 指定的层中。
.. _class_NavigationPolygon_constant_PARSED_GEOMETRY_BOTH:
.. rst-class:: classref-enumeration-constant
:ref:`ParsedGeometryType<enum_NavigationPolygon_ParsedGeometryType>` **PARSED_GEOMETRY_BOTH** = ``2``
:ref:`PARSED_GEOMETRY_MESH_INSTANCES<class_NavigationPolygon_constant_PARSED_GEOMETRY_MESH_INSTANCES>`:ref:`PARSED_GEOMETRY_STATIC_COLLIDERS<class_NavigationPolygon_constant_PARSED_GEOMETRY_STATIC_COLLIDERS>`.
.. _class_NavigationPolygon_constant_PARSED_GEOMETRY_MAX:
.. rst-class:: classref-enumeration-constant
:ref:`ParsedGeometryType<enum_NavigationPolygon_ParsedGeometryType>` **PARSED_GEOMETRY_MAX** = ``3``
代表 :ref:`ParsedGeometryType<enum_NavigationPolygon_ParsedGeometryType>` 枚举的大小。
.. rst-class:: classref-item-separator
----
.. _enum_NavigationPolygon_SourceGeometryMode:
.. rst-class:: classref-enumeration
enum **SourceGeometryMode**: :ref:`🔗<enum_NavigationPolygon_SourceGeometryMode>`
.. _class_NavigationPolygon_constant_SOURCE_GEOMETRY_ROOT_NODE_CHILDREN:
.. rst-class:: classref-enumeration-constant
:ref:`SourceGeometryMode<enum_NavigationPolygon_SourceGeometryMode>` **SOURCE_GEOMETRY_ROOT_NODE_CHILDREN** = ``0``
在根节点的子节点中递归扫描几何体。
.. _class_NavigationPolygon_constant_SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN:
.. rst-class:: classref-enumeration-constant
:ref:`SourceGeometryMode<enum_NavigationPolygon_SourceGeometryMode>` **SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN** = ``1``
以递归方式扫描组中的节点及其子节点以获取几何图形。该组由 :ref:`source_geometry_group_name<class_NavigationPolygon_property_source_geometry_group_name>` 指定。
.. _class_NavigationPolygon_constant_SOURCE_GEOMETRY_GROUPS_EXPLICIT:
.. rst-class:: classref-enumeration-constant
:ref:`SourceGeometryMode<enum_NavigationPolygon_SourceGeometryMode>` **SOURCE_GEOMETRY_GROUPS_EXPLICIT** = ``2``
将组中的节点用于几何。该组由 :ref:`source_geometry_group_name<class_NavigationPolygon_property_source_geometry_group_name>` 指定。
.. _class_NavigationPolygon_constant_SOURCE_GEOMETRY_MAX:
.. rst-class:: classref-enumeration-constant
:ref:`SourceGeometryMode<enum_NavigationPolygon_SourceGeometryMode>` **SOURCE_GEOMETRY_MAX** = ``3``
代表 :ref:`SourceGeometryMode<enum_NavigationPolygon_SourceGeometryMode>` 枚举的大小。
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
属性说明
--------
.. _class_NavigationPolygon_property_agent_radius:
.. rst-class:: classref-property
:ref:`float<class_float>` **agent_radius** = ``10.0`` :ref:`🔗<class_NavigationPolygon_property_agent_radius>`
.. rst-class:: classref-property-setget
- |void| **set_agent_radius**\ (\ value\: :ref:`float<class_float>`\ )
- :ref:`float<class_float>` **get_agent_radius**\ (\ )
烘焙导航网格时侵蚀/收缩可行走表面的距离。
.. rst-class:: classref-item-separator
----
.. _class_NavigationPolygon_property_baking_rect:
.. rst-class:: classref-property
:ref:`Rect2<class_Rect2>` **baking_rect** = ``Rect2(0, 0, 0, 0)`` :ref:`🔗<class_NavigationPolygon_property_baking_rect>`
.. rst-class:: classref-property-setget
- |void| **set_baking_rect**\ (\ value\: :ref:`Rect2<class_Rect2>`\ )
- :ref:`Rect2<class_Rect2>` **get_baking_rect**\ (\ )
如果烘焙的 :ref:`Rect2<class_Rect2>` 存在面积,则导航网格烘焙将被限制在其封闭区域内。
.. rst-class:: classref-item-separator
----
.. _class_NavigationPolygon_property_baking_rect_offset:
.. rst-class:: classref-property
:ref:`Vector2<class_Vector2>` **baking_rect_offset** = ``Vector2(0, 0)`` :ref:`🔗<class_NavigationPolygon_property_baking_rect_offset>`
.. rst-class:: classref-property-setget
- |void| **set_baking_rect_offset**\ (\ value\: :ref:`Vector2<class_Vector2>`\ )
- :ref:`Vector2<class_Vector2>` **get_baking_rect_offset**\ (\ )
应用于 :ref:`baking_rect<class_NavigationPolygon_property_baking_rect>` :ref:`Rect2<class_Rect2>` 的位置偏移量。
.. rst-class:: classref-item-separator
----
.. _class_NavigationPolygon_property_border_size:
.. rst-class:: classref-property
:ref:`float<class_float>` **border_size** = ``0.0`` :ref:`🔗<class_NavigationPolygon_property_border_size>`
.. rst-class:: classref-property-setget
- |void| **set_border_size**\ (\ value\: :ref:`float<class_float>`\ )
- :ref:`float<class_float>` **get_border_size**\ (\ )
:ref:`baking_rect<class_NavigationPolygon_property_baking_rect>` :ref:`Rect2<class_Rect2>` 定义的烘焙边界区域周围的不可导航边框的大小。
:ref:`baking_rect<class_NavigationPolygon_property_baking_rect>` 结合使用,边框大小可用于烘焙图块对齐的导航网格,而图块边缘不会因 :ref:`agent_radius<class_NavigationPolygon_property_agent_radius>` 而缩小。
.. rst-class:: classref-item-separator
----
.. _class_NavigationPolygon_property_cell_size:
.. rst-class:: classref-property
:ref:`float<class_float>` **cell_size** = ``1.0`` :ref:`🔗<class_NavigationPolygon_property_cell_size>`
.. rst-class:: classref-property-setget
- |void| **set_cell_size**\ (\ value\: :ref:`float<class_float>`\ )
- :ref:`float<class_float>` **get_cell_size**\ (\ )
用于将导航网格顶点栅格化的单元格大小。必须与导航地图上的单元格大小相匹配。
.. rst-class:: classref-item-separator
----
.. _class_NavigationPolygon_property_parsed_collision_mask:
.. rst-class:: classref-property
:ref:`int<class_int>` **parsed_collision_mask** = ``4294967295`` :ref:`🔗<class_NavigationPolygon_property_parsed_collision_mask>`
.. rst-class:: classref-property-setget
- |void| **set_parsed_collision_mask**\ (\ value\: :ref:`int<class_int>`\ )
- :ref:`int<class_int>` **get_parsed_collision_mask**\ (\ )
用于扫描静态碰撞器的物理层。
仅在 :ref:`parsed_geometry_type<class_NavigationPolygon_property_parsed_geometry_type>`:ref:`PARSED_GEOMETRY_STATIC_COLLIDERS<class_NavigationPolygon_constant_PARSED_GEOMETRY_STATIC_COLLIDERS>`:ref:`PARSED_GEOMETRY_BOTH<class_NavigationPolygon_constant_PARSED_GEOMETRY_BOTH>` 时才使用。
.. rst-class:: classref-item-separator
----
.. _class_NavigationPolygon_property_parsed_geometry_type:
.. rst-class:: classref-property
:ref:`ParsedGeometryType<enum_NavigationPolygon_ParsedGeometryType>` **parsed_geometry_type** = ``2`` :ref:`🔗<class_NavigationPolygon_property_parsed_geometry_type>`
.. rst-class:: classref-property-setget
- |void| **set_parsed_geometry_type**\ (\ value\: :ref:`ParsedGeometryType<enum_NavigationPolygon_ParsedGeometryType>`\ )
- :ref:`ParsedGeometryType<enum_NavigationPolygon_ParsedGeometryType>` **get_parsed_geometry_type**\ (\ )
决定哪种类型的节点可解析为几何图形。可能的取值见 :ref:`ParsedGeometryType<enum_NavigationPolygon_ParsedGeometryType>`\ 。
.. rst-class:: classref-item-separator
----
.. _class_NavigationPolygon_property_source_geometry_group_name:
.. rst-class:: classref-property
:ref:`StringName<class_StringName>` **source_geometry_group_name** = ``&"navigation_polygon_source_geometry_group"`` :ref:`🔗<class_NavigationPolygon_property_source_geometry_group_name>`
.. rst-class:: classref-property-setget
- |void| **set_source_geometry_group_name**\ (\ value\: :ref:`StringName<class_StringName>`\ )
- :ref:`StringName<class_StringName>` **get_source_geometry_group_name**\ (\ )
应被解析以烘焙源几何体的节点的组名称。
只有当 :ref:`source_geometry_mode<class_NavigationPolygon_property_source_geometry_mode>`:ref:`SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN<class_NavigationPolygon_constant_SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN>`:ref:`SOURCE_GEOMETRY_GROUPS_EXPLICIT<class_NavigationPolygon_constant_SOURCE_GEOMETRY_GROUPS_EXPLICIT>` 时才使用。
.. rst-class:: classref-item-separator
----
.. _class_NavigationPolygon_property_source_geometry_mode:
.. rst-class:: classref-property
:ref:`SourceGeometryMode<enum_NavigationPolygon_SourceGeometryMode>` **source_geometry_mode** = ``0`` :ref:`🔗<class_NavigationPolygon_property_source_geometry_mode>`
.. rst-class:: classref-property-setget
- |void| **set_source_geometry_mode**\ (\ value\: :ref:`SourceGeometryMode<enum_NavigationPolygon_SourceGeometryMode>`\ )
- :ref:`SourceGeometryMode<enum_NavigationPolygon_SourceGeometryMode>` **get_source_geometry_mode**\ (\ )
烘焙时使用的几何体的来源。可能的取值见 :ref:`SourceGeometryMode<enum_NavigationPolygon_SourceGeometryMode>`\ 。
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
方法说明
--------
.. _class_NavigationPolygon_method_add_outline:
.. rst-class:: classref-method
|void| **add_outline**\ (\ outline\: :ref:`PackedVector2Array<class_PackedVector2Array>`\ ) :ref:`🔗<class_NavigationPolygon_method_add_outline>`
将包含轮廓顶点的 :ref:`PackedVector2Array<class_PackedVector2Array>` 追加到包含所有轮廓的内部数组。
.. rst-class:: classref-item-separator
----
.. _class_NavigationPolygon_method_add_outline_at_index:
.. rst-class:: classref-method
|void| **add_outline_at_index**\ (\ outline\: :ref:`PackedVector2Array<class_PackedVector2Array>`, index\: :ref:`int<class_int>`\ ) :ref:`🔗<class_NavigationPolygon_method_add_outline_at_index>`
将一个包含轮廓顶点的 :ref:`PackedVector2Array<class_PackedVector2Array>` 添加到包含固定位置处的所有轮廓的内部数组。
.. rst-class:: classref-item-separator
----
.. _class_NavigationPolygon_method_add_polygon:
.. rst-class:: classref-method
|void| **add_polygon**\ (\ polygon\: :ref:`PackedInt32Array<class_PackedInt32Array>`\ ) :ref:`🔗<class_NavigationPolygon_method_add_polygon>`
使用调用 :ref:`get_vertices<class_NavigationPolygon_method_get_vertices>` 得到的顶点的索引添加一个多边形。
.. rst-class:: classref-item-separator
----
.. _class_NavigationPolygon_method_clear:
.. rst-class:: classref-method
|void| **clear**\ (\ ) :ref:`🔗<class_NavigationPolygon_method_clear>`
清除顶点和多边形索引的内部数组。
.. rst-class:: classref-item-separator
----
.. _class_NavigationPolygon_method_clear_outlines:
.. rst-class:: classref-method
|void| **clear_outlines**\ (\ ) :ref:`🔗<class_NavigationPolygon_method_clear_outlines>`
清除轮廓数组,但不清除顶点和由顶点创建的多边形。
.. rst-class:: classref-item-separator
----
.. _class_NavigationPolygon_method_clear_polygons:
.. rst-class:: classref-method
|void| **clear_polygons**\ (\ ) :ref:`🔗<class_NavigationPolygon_method_clear_polygons>`
清除多边形数组,但不清除轮廓和顶点数组。
.. rst-class:: classref-item-separator
----
.. _class_NavigationPolygon_method_get_navigation_mesh:
.. rst-class:: classref-method
:ref:`NavigationMesh<class_NavigationMesh>` **get_navigation_mesh**\ (\ ) :ref:`🔗<class_NavigationPolygon_method_get_navigation_mesh>`
返回由该导航多边形产生的 :ref:`NavigationMesh<class_NavigationMesh>`\ 。该导航网格可用于使用 :ref:`NavigationServer3D.region_set_navigation_mesh<class_NavigationServer3D_method_region_set_navigation_mesh>` API 直接更新区块的导航网格(因为 2D 在幕后使用 3D 服务器)。
.. rst-class:: classref-item-separator
----
.. _class_NavigationPolygon_method_get_outline:
.. rst-class:: classref-method
:ref:`PackedVector2Array<class_PackedVector2Array>` **get_outline**\ (\ idx\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_NavigationPolygon_method_get_outline>`
返回一个 :ref:`PackedVector2Array<class_PackedVector2Array>`\ ,其中包含在编辑器中或通过脚本创建的轮廓的顶点。
.. rst-class:: classref-item-separator
----
.. _class_NavigationPolygon_method_get_outline_count:
.. rst-class:: classref-method
:ref:`int<class_int>` **get_outline_count**\ (\ ) |const| :ref:`🔗<class_NavigationPolygon_method_get_outline_count>`
返回在编辑器或脚本中创建的轮廓的数量。
.. rst-class:: classref-item-separator
----
.. _class_NavigationPolygon_method_get_parsed_collision_mask_value:
.. rst-class:: classref-method
:ref:`bool<class_bool>` **get_parsed_collision_mask_value**\ (\ layer_number\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_NavigationPolygon_method_get_parsed_collision_mask_value>`
返回 :ref:`parsed_collision_mask<class_NavigationPolygon_property_parsed_collision_mask>` 中是否启用了指定的层,给定的 ``layer_number`` 应在 1 和 32 之间。
.. rst-class:: classref-item-separator
----
.. _class_NavigationPolygon_method_get_polygon:
.. rst-class:: classref-method
:ref:`PackedInt32Array<class_PackedInt32Array>` **get_polygon**\ (\ idx\: :ref:`int<class_int>`\ ) :ref:`🔗<class_NavigationPolygon_method_get_polygon>`
返回创建多边形的顶点索引,形式为 :ref:`PackedInt32Array<class_PackedInt32Array>`\ 。
.. rst-class:: classref-item-separator
----
.. _class_NavigationPolygon_method_get_polygon_count:
.. rst-class:: classref-method
:ref:`int<class_int>` **get_polygon_count**\ (\ ) |const| :ref:`🔗<class_NavigationPolygon_method_get_polygon_count>`
返回多边形的数量。
.. rst-class:: classref-item-separator
----
.. _class_NavigationPolygon_method_get_vertices:
.. rst-class:: classref-method
:ref:`PackedVector2Array<class_PackedVector2Array>` **get_vertices**\ (\ ) |const| :ref:`🔗<class_NavigationPolygon_method_get_vertices>`
返回一个 :ref:`PackedVector2Array<class_PackedVector2Array>`\ ,其中包含用于创建多边形的所有顶点。
.. rst-class:: classref-item-separator
----
.. _class_NavigationPolygon_method_make_polygons_from_outlines:
.. rst-class:: classref-method
|void| **make_polygons_from_outlines**\ (\ ) :ref:`🔗<class_NavigationPolygon_method_make_polygons_from_outlines>`
**已弃用:** Use :ref:`NavigationServer2D.parse_source_geometry_data<class_NavigationServer2D_method_parse_source_geometry_data>` and :ref:`NavigationServer2D.bake_from_source_geometry_data<class_NavigationServer2D_method_bake_from_source_geometry_data>` instead.
从编辑器中添加的轮廓或通过脚本创建多边形。
.. rst-class:: classref-item-separator
----
.. _class_NavigationPolygon_method_remove_outline:
.. rst-class:: classref-method
|void| **remove_outline**\ (\ idx\: :ref:`int<class_int>`\ ) :ref:`🔗<class_NavigationPolygon_method_remove_outline>`
删除在编辑器或脚本中创建的轮廓。你必须调用 :ref:`make_polygons_from_outlines<class_NavigationPolygon_method_make_polygons_from_outlines>` 来更新多边形。
.. rst-class:: classref-item-separator
----
.. _class_NavigationPolygon_method_set_outline:
.. rst-class:: classref-method
|void| **set_outline**\ (\ idx\: :ref:`int<class_int>`, outline\: :ref:`PackedVector2Array<class_PackedVector2Array>`\ ) :ref:`🔗<class_NavigationPolygon_method_set_outline>`
更改在编辑器或脚本中创建的轮廓。你必须调用 :ref:`make_polygons_from_outlines<class_NavigationPolygon_method_make_polygons_from_outlines>` 来更新多边形。
.. rst-class:: classref-item-separator
----
.. _class_NavigationPolygon_method_set_parsed_collision_mask_value:
.. rst-class:: classref-method
|void| **set_parsed_collision_mask_value**\ (\ layer_number\: :ref:`int<class_int>`, value\: :ref:`bool<class_bool>`\ ) :ref:`🔗<class_NavigationPolygon_method_set_parsed_collision_mask_value>`
根据 ``value``\ ,启用或禁用 :ref:`parsed_collision_mask<class_NavigationPolygon_property_parsed_collision_mask>` 中指定的层,给定的 ``layer_number`` 应在 1 和 32 之间。
.. rst-class:: classref-item-separator
----
.. _class_NavigationPolygon_method_set_vertices:
.. rst-class:: classref-method
|void| **set_vertices**\ (\ vertices\: :ref:`PackedVector2Array<class_PackedVector2Array>`\ ) :ref:`🔗<class_NavigationPolygon_method_set_vertices>`
设置顶点,可以使用 :ref:`add_polygon<class_NavigationPolygon_method_add_polygon>` 方法对其进行索引,创建多边形。
.. |virtual| replace:: :abbr:`virtual (本方法通常需要用户覆盖才能生效。)`
.. |const| replace:: :abbr:`const (本方法无副作用,不会修改该实例的任何成员变量。)`
.. |vararg| replace:: :abbr:`vararg (本方法除了能接受在此处描述的参数外,还能够继续接受任意数量的参数。)`
.. |constructor| replace:: :abbr:`constructor (本方法用于构造某个类型。)`
.. |static| replace:: :abbr:`static (调用本方法无需实例,可直接使用类名进行调用。)`
.. |operator| replace:: :abbr:`operator (本方法描述的是使用本类型作为左操作数的有效运算符。)`
.. |bitfield| replace:: :abbr:`BitField (这个值是由下列位标志构成位掩码的整数。)`
.. |void| replace:: :abbr:`void (无返回值。)`