:github_url: hide .. _class_NavigationLink2D: NavigationLink2D ================ **实验性:** This class may be changed or removed in future versions. **继承:** :ref:`Node2D` **<** :ref:`CanvasItem` **<** :ref:`Node` **<** :ref:`Object` 连接两个位于 :ref:`NavigationRegion2D` 上的位置的链接,导航时能够让代理走这个链接。 .. rst-class:: classref-introduction-group 描述 ---- 连接两个位于 :ref:`NavigationRegion2D` 上的位置的链接,导航时能够让代理走这个链接。这两个位置可以在同一个 :ref:`NavigationRegion2D` 上,也可以是在两个不同的区块上。链接可以用来表达沿着导航多边形表面行进以外的导航方法,例如滑锁、传送、跳过沟壑等等。 .. rst-class:: classref-introduction-group 教程 ---- - :doc:`使用 NavigationLink <../tutorials/navigation/navigation_using_navigationlinks>` .. rst-class:: classref-reftable-group 属性 ---- .. table:: :widths: auto +-------------------------------+-----------------------------------------------------------------------------+-------------------+ | :ref:`bool` | :ref:`bidirectional` | ``true`` | +-------------------------------+-----------------------------------------------------------------------------+-------------------+ | :ref:`bool` | :ref:`enabled` | ``true`` | +-------------------------------+-----------------------------------------------------------------------------+-------------------+ | :ref:`Vector2` | :ref:`end_position` | ``Vector2(0, 0)`` | +-------------------------------+-----------------------------------------------------------------------------+-------------------+ | :ref:`float` | :ref:`enter_cost` | ``0.0`` | +-------------------------------+-----------------------------------------------------------------------------+-------------------+ | :ref:`int` | :ref:`navigation_layers` | ``1`` | +-------------------------------+-----------------------------------------------------------------------------+-------------------+ | :ref:`Vector2` | :ref:`start_position` | ``Vector2(0, 0)`` | +-------------------------------+-----------------------------------------------------------------------------+-------------------+ | :ref:`float` | :ref:`travel_cost` | ``1.0`` | +-------------------------------+-----------------------------------------------------------------------------+-------------------+ .. rst-class:: classref-reftable-group 方法 ---- .. table:: :widths: auto +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2` | :ref:`get_global_end_position`\ (\ ) |const| | +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2` | :ref:`get_global_start_position`\ (\ ) |const| | +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`get_navigation_layer_value`\ (\ layer_number\: :ref:`int`\ ) |const| | +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`RID` | :ref:`get_navigation_map`\ (\ ) |const| | +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`RID` | :ref:`get_rid`\ (\ ) |const| | +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`set_global_end_position`\ (\ position\: :ref:`Vector2`\ ) | +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`set_global_start_position`\ (\ position\: :ref:`Vector2`\ ) | +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`set_navigation_layer_value`\ (\ layer_number\: :ref:`int`, value\: :ref:`bool`\ ) | +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`set_navigation_map`\ (\ navigation_map\: :ref:`RID`\ ) | +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group 属性说明 -------- .. _class_NavigationLink2D_property_bidirectional: .. rst-class:: classref-property :ref:`bool` **bidirectional** = ``true`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_bidirectional**\ (\ value\: :ref:`bool`\ ) - :ref:`bool` **is_bidirectional**\ (\ ) 返回这个连接是可以双向通行,还是只能从 :ref:`start_position` 通向 :ref:`end_position`\ 。 .. rst-class:: classref-item-separator ---- .. _class_NavigationLink2D_property_enabled: .. rst-class:: classref-property :ref:`bool` **enabled** = ``true`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_enabled**\ (\ value\: :ref:`bool`\ ) - :ref:`bool` **is_enabled**\ (\ ) 该链接当前是否处于活动状态。如果为 ``false`` ,则 :ref:`NavigationServer2D.map_get_path()` 会忽略这个链接。 .. rst-class:: classref-item-separator ---- .. _class_NavigationLink2D_property_end_position: .. rst-class:: classref-property :ref:`Vector2` **end_position** = ``Vector2(0, 0)`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_end_position**\ (\ value\: :ref:`Vector2`\ ) - :ref:`Vector2` **get_end_position**\ (\ ) 链接的结束位置。 链接会搜索导航网格中最接近这个位置的多边形,并将自身与该多边形相关联。 链接搜索的距离由 :ref:`NavigationServer2D.map_set_link_connection_radius()` 控制。 .. rst-class:: classref-item-separator ---- .. _class_NavigationLink2D_property_enter_cost: .. rst-class:: classref-property :ref:`float` **enter_cost** = ``0.0`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_enter_cost**\ (\ value\: :ref:`float`\ ) - :ref:`float` **get_enter_cost**\ (\ ) 当寻路从其他地区的导航网格进入该链接时,\ :ref:`enter_cost` 会加到路径距离中,用于确定最短路径。 .. rst-class:: classref-item-separator ---- .. _class_NavigationLink2D_property_navigation_layers: .. rst-class:: classref-property :ref:`int` **navigation_layers** = ``1`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_navigation_layers**\ (\ value\: :ref:`int`\ ) - :ref:`int` **get_navigation_layers**\ (\ ) 决定链接所属导航层的位域。使用 :ref:`NavigationServer2D.map_get_path()` 请求路径时会检查这些导航层。 .. rst-class:: classref-item-separator ---- .. _class_NavigationLink2D_property_start_position: .. rst-class:: classref-property :ref:`Vector2` **start_position** = ``Vector2(0, 0)`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_start_position**\ (\ value\: :ref:`Vector2`\ ) - :ref:`Vector2` **get_start_position**\ (\ ) 链接的起始位置。 链接会搜索导航网格中最接近这个位置的多边形,并将自身与该多边形相关联。 链接搜索的距离由 :ref:`NavigationServer2D.map_set_link_connection_radius()` 控制。 .. rst-class:: classref-item-separator ---- .. _class_NavigationLink2D_property_travel_cost: .. rst-class:: classref-property :ref:`float` **travel_cost** = ``1.0`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_travel_cost**\ (\ value\: :ref:`float`\ ) - :ref:`float` **get_travel_cost**\ (\ ) 当寻路沿着该链接移动时,移动距离会和 :ref:`travel_cost` 相乘,用于确定最短路径。 .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group 方法说明 -------- .. _class_NavigationLink2D_method_get_global_end_position: .. rst-class:: classref-method :ref:`Vector2` **get_global_end_position**\ (\ ) |const| :ref:`🔗` 返回该链接的 :ref:`end_position` 的全局位置。 .. rst-class:: classref-item-separator ---- .. _class_NavigationLink2D_method_get_global_start_position: .. rst-class:: classref-method :ref:`Vector2` **get_global_start_position**\ (\ ) |const| :ref:`🔗` 返回该链接的 :ref:`start_position` 的全局位置。 .. rst-class:: classref-item-separator ---- .. _class_NavigationLink2D_method_get_navigation_layer_value: .. rst-class:: classref-method :ref:`bool` **get_navigation_layer_value**\ (\ layer_number\: :ref:`int`\ ) |const| :ref:`🔗` 返回 :ref:`navigation_layers` 位掩码中指定的层是否启用,给定的 ``layer_number`` 应在 1 和 32 之间。 .. rst-class:: classref-item-separator ---- .. _class_NavigationLink2D_method_get_navigation_map: .. rst-class:: classref-method :ref:`RID` **get_navigation_map**\ (\ ) |const| :ref:`🔗` 返回该链接使用的当前导航地图 :ref:`RID`\ 。 .. rst-class:: classref-item-separator ---- .. _class_NavigationLink2D_method_get_rid: .. rst-class:: classref-method :ref:`RID` **get_rid**\ (\ ) |const| :ref:`🔗` 返回 :ref:`NavigationServer2D` 上该链接的 :ref:`RID`\ 。 .. rst-class:: classref-item-separator ---- .. _class_NavigationLink2D_method_set_global_end_position: .. rst-class:: classref-method |void| **set_global_end_position**\ (\ position\: :ref:`Vector2`\ ) :ref:`🔗` 使用全局位置 ``position`` 设置相对于链接的结束位置 :ref:`end_position`\ 。 .. rst-class:: classref-item-separator ---- .. _class_NavigationLink2D_method_set_global_start_position: .. rst-class:: classref-method |void| **set_global_start_position**\ (\ position\: :ref:`Vector2`\ ) :ref:`🔗` 使用全局位置 ``position`` 设置相对于链接的起始位置 :ref:`start_position`\ 。 .. rst-class:: classref-item-separator ---- .. _class_NavigationLink2D_method_set_navigation_layer_value: .. rst-class:: classref-method |void| **set_navigation_layer_value**\ (\ layer_number\: :ref:`int`, value\: :ref:`bool`\ ) :ref:`🔗` 根据 ``value``\ ,启用或禁用 :ref:`navigation_layers` 位掩码中指定的层,给定的 ``layer_number`` 应在 1 和 32 之间。 .. rst-class:: classref-item-separator ---- .. _class_NavigationLink2D_method_set_navigation_map: .. rst-class:: classref-method |void| **set_navigation_map**\ (\ navigation_map\: :ref:`RID`\ ) :ref:`🔗` 设置该链接应使用的导航地图的 :ref:`RID`\ 。默认情况下,该链接会自动加入 :ref:`World2D` 默认导航地图,因此该函数只需要覆盖默认地图即可。 .. |virtual| replace:: :abbr:`virtual (本方法通常需要用户覆盖才能生效。)` .. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)` .. |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 (无返回值。)`