Skip to content

Commit

Permalink
Merge pull request #9813 from ShawnHardern/update-using-navigation-re…
Browse files Browse the repository at this point in the history
…gions-csharp

Add C# examples to Using NavigationRegions
  • Loading branch information
AThousandShips authored Aug 23, 2024
2 parents f3ddfc3 + 6a68d3e commit 69fe8f0
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tutorials/navigation/navigation_using_navigationregions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,32 @@ The region RID can then be obtained from NavigationRegion Nodes with ``get_rid()

var navigationserver_region_rid: RID = get_rid()

.. code-tab:: csharp 2D C#

public partial class MyNavigationRegion2D : NavigationRegion2D
{
public override void _Ready()
{
Rid navigationServerRegionRid = GetRid();
}
}

.. code-tab:: gdscript 3D GDScript

extends NavigationRegion3D

var navigationserver_region_rid: RID = get_rid()

.. code-tab:: csharp 3D C#

public partial class MyNavigationRegion3D : NavigationRegion3D
{
public override void _Ready()
{
Rid navigationServerRegionRid = GetRid();
}
}

New regions can also be created with the NavigationServer API and added to any existing map.

If regions are created with the NavigationServer API directly they need to be assigned a navigation map manually.
Expand All @@ -65,6 +85,18 @@ If regions are created with the NavigationServer API directly they need to be as
var default_map_rid: RID = get_world_2d().get_navigation_map()
NavigationServer2D.region_set_map(new_region_rid, default_map_rid)

.. code-tab:: csharp 2D C#

public partial class MyNode2D : Node2D
{
public override void _Ready()
{
Rid newRegionRid = NavigationServer2D.RegionCreate();
Rid defaultMapRid = GetWorld2D().NavigationMap;
NavigationServer2D.RegionSetMap(newRegionRid, defaultMapRid);
}
}

.. code-tab:: gdscript 3D GDScript

extends Node3D
Expand All @@ -74,6 +106,18 @@ If regions are created with the NavigationServer API directly they need to be as
var default_map_rid: RID = get_world_3d().get_navigation_map()
NavigationServer3D.region_set_map(new_region_rid, default_map_rid)

.. code-tab:: csharp 3D C#

public partial class MyNode3D : Node3D
{
public override void _Ready()
{
Rid newRegionRid = NavigationServer3D.RegionCreate();
Rid defaultMapRid = GetWorld3D().NavigationMap;
NavigationServer3D.RegionSetMap(newRegionRid, defaultMapRid);
}
}

.. note::

Navigation regions can only be assigned to a single navigation map.
Expand Down

0 comments on commit 69fe8f0

Please sign in to comment.