19.1 C
New York

unity – Is it attainable to launch the default OpenXR runtime app dynamically?


I’ve a Unity sport that I want to make suitable with VR and desktop each in the identical mission.

I’ve a script that calls XRGeneralSettings.Occasion.Supervisor.InitializeLoaderSync(); and XRGeneralSettings.Occasion.Supervisor.StartSubsystems(); when the app launches, so long as no --disable-vr argument was handed.

This script partially works as supposed, and it launches into VR, however it requires the lively OpenXR runtime (SteamVR, in my case) to be working, else it can fail to initialize.

I would love my app to mechanically launch the participant’s default OpenXR runtime app, moderately than having to have them launch it themselves, then launch the sport afterwards.

The total script is as follows:

utilizing System;
utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing System.Linq;
utilizing UnityEngine;
utilizing UnityEngine.XR.Administration;
public class DynamicOpenXR : MonoBehaviour
{
    personal const bool TestingDesktop = false;
    personal string[] commandLineArgs;

    public static bool IsInVRMode = false; // This is not but used.
    
    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSplashScreen)]
    void Awake()
    {
        commandLineArgs = TestingDesktop ? new[] { "Nexus.exe", "--disable-vr" } : Atmosphere.GetCommandLineArgs();

        if (commandLineArgs.Incorporates("--disable-vr", StringComparer.CurrentCultureIgnoreCase))
        {
            Debug.Log("Disable VR command line argument detected. Not enabling VR.");
        }
        else
        {
            Debug.Log("No VR disable argument detected. Initializing OpenXR.");
            StartCoroutine(InitializeOpenXR());
        }

        enabled = false;
    }

    personal void OnApplicationQuit()
    {
        if (XRGeneralSettings.Occasion.Supervisor.activeLoader == null) return;
        
        Debug.Log("Shutting down OpenXR...");
        StartCoroutine(DeinitializeOpenXR());
    }

    IEnumerator DeinitializeOpenXR()
    {
        XRGeneralSettings.Occasion.Supervisor.StopSubsystems();
        yield return null;
        
        XRGeneralSettings.Occasion.Supervisor.DeinitializeLoader();
    }

    IEnumerator InitializeOpenXR()
    {
        XRGeneralSettings.Occasion.Supervisor.InitializeLoaderSync();
        yield return null;

        whereas (!XRGeneralSettings.Occasion.Supervisor.isInitializationComplete)
            yield return null;

        XRGeneralSettings.Occasion.Supervisor.StartSubsystems();
        yield return null;
    }
}

Any assistance is appreciated, thanks!

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles