Jelajahi Sumber

Add C# examples to Using NavigationRegions

Co-authored-by: A Thousand Ships <[email protected]>
Co-authored-by: Raul Santos <[email protected]>
Shawn Hardern 11 bulan lalu
induk
melakukan
6a68d3e5c0
1 mengubah file dengan 44 tambahan dan 0 penghapusan
  1. 44 0
      tutorials/navigation/navigation_using_navigationregions.rst

+ 44 - 0
tutorials/navigation/navigation_using_navigationregions.rst

@@ -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.
@@ -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
@@ -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.