NAK_CVR_Mods/DesktopVRSwitch/VRModeSwitchDebugger.cs
NotAKidoS 337134d2b5 [DesktopVRSwitch] Prevent SteamVR_Behaviour from closing game.
Was going to use my own event and switch before quit, but SteamVR_Behaviour was the one doing it the entire time. Very convenient for me.
2023-06-20 15:15:42 -05:00

42 lines
890 B
C#

using System.Collections;
using UnityEngine;
namespace NAK.DesktopVRSwitch;
class VRModeSwitchDebugger : MonoBehaviour
{
Coroutine _switchCoroutine;
WaitForSeconds _sleep;
void OnEnable()
{
if (_switchCoroutine == null)
{
_switchCoroutine = StartCoroutine(SwitchLoop());
_sleep = new WaitForSeconds(2f);
}
}
void OnDisable()
{
if (_switchCoroutine != null)
{
StopCoroutine(_switchCoroutine);
_switchCoroutine = null;
_sleep = null;
}
}
IEnumerator SwitchLoop()
{
while (true)
{
if (!VRModeSwitchManager.Instance.SwitchInProgress)
{
VRModeSwitchManager.Instance.AttemptSwitch();
yield return _sleep;
}
yield return null;
}
}
}