Browse Source

Add C# examples to Using NavigationRegions

Co-authored-by: A Thousand Ships <[email protected]>
Co-authored-by: Raul Santos <[email protected]>
Shawn Hardern 11 tháng trước cách đây
mục cha
commit
6a68d3e5c0

+ 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()
     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
  .. code-tab:: gdscript 3D GDScript
 
 
     extends NavigationRegion3D
     extends NavigationRegion3D
 
 
     var navigationserver_region_rid: RID = get_rid()
     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.
 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.
 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()
         var default_map_rid: RID = get_world_2d().get_navigation_map()
         NavigationServer2D.region_set_map(new_region_rid, default_map_rid)
         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
  .. code-tab:: gdscript 3D GDScript
 
 
     extends Node3D
     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()
         var default_map_rid: RID = get_world_3d().get_navigation_map()
         NavigationServer3D.region_set_map(new_region_rid, default_map_rid)
         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::
 .. note::
 
 
     Navigation regions can only be assigned to a single navigation map.
     Navigation regions can only be assigned to a single navigation map.