You've already forked zumbi-game
add script to check if VR headset is connected
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR;
|
||||
using UnityEngine.XR.Management;
|
||||
|
||||
public class StartupHeadsetCheck : MonoBehaviour
|
||||
{
|
||||
#if UNITY_STANDALONE_WIN && !UNITY_EDITOR
|
||||
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
|
||||
private static extern int MessageBox(System.IntPtr hWnd, string text, string caption, uint type);
|
||||
#endif
|
||||
|
||||
private IEnumerator Start()
|
||||
{
|
||||
// Let OpenXR/XR Management initialize.
|
||||
yield return null;
|
||||
yield return null;
|
||||
yield return null;
|
||||
|
||||
if (!IsOpenXRRunning())
|
||||
{
|
||||
ShowWindowsErrorMessage();
|
||||
Application.Quit();
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsOpenXRRunning()
|
||||
{
|
||||
XRManagerSettings xrManager = XRGeneralSettings.Instance?.Manager;
|
||||
|
||||
if (xrManager == null || xrManager.activeLoader == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var displays = new List<XRDisplaySubsystem>();
|
||||
SubsystemManager.GetSubsystems(displays);
|
||||
|
||||
foreach (XRDisplaySubsystem display in displays)
|
||||
{
|
||||
if (display.running)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void ShowWindowsErrorMessage()
|
||||
{
|
||||
#if UNITY_STANDALONE_WIN && !UNITY_EDITOR
|
||||
MessageBox(
|
||||
System.IntPtr.Zero,
|
||||
"No VR headset detected.\n\n" +
|
||||
"Please connect your headset and make sure your OpenXR runtime is active.\n\n" +
|
||||
"SteamVR headset: start SteamVR.\n" +
|
||||
"Meta Quest Link/Air Link: start Meta Quest Link.\n" +
|
||||
"WMR headset: start Mixed Reality Portal.\n\n" +
|
||||
"Then restart the game.",
|
||||
"VR Headset Not Detected",
|
||||
0x10 // MB_ICONERROR
|
||||
);
|
||||
#else
|
||||
Debug.LogError("No VR headset detected.");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user