Bläddra i källkod

Added a C# tutorial for the "Setting up XR"-section (#7352)

Co-authored-by: Raul Santos <[email protected]>
Co-authored-by: Ashtreighlia <[email protected]>
Ashley 2 år sedan
förälder
incheckning
9dcef8a465
1 ändrade filer med 34 tillägg och 5 borttagningar
  1. 34 5
      tutorials/xr/setting_up_xr.rst

+ 34 - 5
tutorials/xr/setting_up_xr.rst

@@ -74,15 +74,16 @@ Right now all these nodes are on the floor, the will be positioned correctly in
 
 Next we need to add a script to our root node. Add the following code into this script:
 
-::
+.. tabs::
+  .. code-tab:: gdscript GDScript
 
     extends Node3D
 
-    var interface: XRInterface
+    var xr_interface: XRInterface
 
     func _ready():
-        interface = XRServer.find_interface("OpenXR")
-        if interface and interface.is_initialized():
+        xr_interface = XRServer.find_interface("OpenXR")
+        if xr_interface and xr_interface.is_initialized():
             print("OpenXR initialised successfully")
 
             # Turn off v-sync!
@@ -91,7 +92,35 @@ Next we need to add a script to our root node. Add the following code into this
             # Change our main viewport to output to the HMD
             get_viewport().use_xr = true
         else:
-            print("OpenXR not initialised, please check if your headset is connected")
+            print("OpenXR not initialized, please check if your headset is connected")
+
+  .. code-tab:: csharp
+
+    using Godot;
+
+    public partial class MyNode3D : Node3D
+    {
+        private XRInterface _xrInterface;
+
+        public override void _Ready()
+        {
+            _xrInterface = XRServer.FindInterface("OpenXR");
+            if(_xrInterface != null && _xrInterface.IsInitialized())
+            {
+                GD.Print("OpenXR initialized successfully");
+
+                // Turn off v-sync!
+                DisplayServer.WindowSetVsyncMode(DisplayServer.VSyncMode.Disabled);
+
+                // Change our main viewport to output to the HMD
+                GetViewport().UseXR = true;
+            }
+            else
+            {
+                GD.Print("OpenXR not initialized, please check if your headset is connected");
+            }
+        }
+    }
 
 This code fragment assumes we are using OpenXR, if you wish to use any of the other interfaces you can change the ``find_interface`` call.