mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 14:29:25 +00:00
[DesktopVRSwitch] Minor changes
This commit is contained in:
parent
6d17085f21
commit
4c09f9bd57
25 changed files with 359 additions and 205 deletions
66
DesktopVRSwitch/XRHandler.cs
Normal file
66
DesktopVRSwitch/XRHandler.cs
Normal file
|
@ -0,0 +1,66 @@
|
|||
using System.Collections;
|
||||
using System.Reflection;
|
||||
using ABI_RC.Core.Savior;
|
||||
using Unity.XR.OpenVR;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR.Management;
|
||||
using UnityEngine.XR.OpenXR;
|
||||
using Valve.VR;
|
||||
|
||||
namespace NAK.DesktopVRSwitch;
|
||||
|
||||
internal static class XRHandler
|
||||
{
|
||||
internal static IEnumerator StartXR()
|
||||
{
|
||||
yield return XRGeneralSettings.Instance.Manager.InitializeLoader();
|
||||
|
||||
if (XRGeneralSettings.Instance.Manager.activeLoader != null)
|
||||
XRGeneralSettings.Instance.Manager.StartSubsystems();
|
||||
else
|
||||
StopXR();
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
internal static IEnumerator StopXR()
|
||||
{
|
||||
if (!XRGeneralSettings.Instance.Manager.isInitializationComplete)
|
||||
yield break;
|
||||
|
||||
// Forces SteamVR to reinitialize SteamVR_Input next switch
|
||||
SteamVR_ActionSet_Manager.DisableAllActionSets();
|
||||
SteamVR_Input.initialized = false;
|
||||
|
||||
// Remove SteamVR behaviour & render
|
||||
UnityEngine.Object.DestroyImmediate(SteamVR_Behaviour.instance.gameObject);
|
||||
SteamVR.enabled = false; // disposes SteamVR
|
||||
|
||||
// Disable UnityXR
|
||||
XRGeneralSettings.Instance.Manager.StopSubsystems();
|
||||
XRGeneralSettings.Instance.Manager.DeinitializeLoader();
|
||||
|
||||
// We don't really need to wait a frame on Stop()
|
||||
yield return null;
|
||||
}
|
||||
|
||||
internal static void SwitchLoader()
|
||||
{
|
||||
XRLoader item;
|
||||
|
||||
if (!CheckVR.Instance.forceOpenXr)
|
||||
{
|
||||
item = ScriptableObject.CreateInstance<OpenVRLoader>();
|
||||
DesktopVRSwitch.Logger.Msg("Using XR Loader: SteamVR");
|
||||
}
|
||||
else
|
||||
{
|
||||
item = ScriptableObject.CreateInstance<OpenXRLoader>();
|
||||
DesktopVRSwitch.Logger.Msg("Using XR Loader: OpenXR");
|
||||
}
|
||||
|
||||
typeof(XRManagerSettings)
|
||||
.GetField("m_Loaders", BindingFlags.Instance | BindingFlags.NonPublic)
|
||||
?.SetValue(XRGeneralSettings.Instance.Manager, new List<XRLoader> { item });
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue