From 9dcef8a465aaa8d2d407eb81067fe54bbc4874cc Mon Sep 17 00:00:00 2001 From: Ashley Date: Tue, 16 May 2023 01:15:58 +0200 Subject: [PATCH] Added a C# tutorial for the "Setting up XR"-section (#7352) Co-authored-by: Raul Santos Co-authored-by: Ashtreighlia --- tutorials/xr/setting_up_xr.rst | 39 +++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/tutorials/xr/setting_up_xr.rst b/tutorials/xr/setting_up_xr.rst index 502eeb8de..b827caf0a 100644 --- a/tutorials/xr/setting_up_xr.rst +++ b/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.