diff --git a/Assets/SteamVR/Scripts/SteamVR.cs b/Assets/SteamVR/Scripts/SteamVR.cs index e82bd305..56da30cb 100644 --- a/Assets/SteamVR/Scripts/SteamVR.cs +++ b/Assets/SteamVR/Scripts/SteamVR.cs @@ -30,7 +30,7 @@ public static bool enabled { get { - if (!XRSettings.enabled) + if (!XRSettings.enabled && !isStandalone) enabled = false; return _enabled; } @@ -84,6 +84,8 @@ public enum InitializedStates public static InitializedStates initializedState = InitializedStates.None; + public static bool isStandalone { get; private set; } = false; + public static void Initialize(bool forceUnityVRMode = false) { if (forceUnityVRMode) @@ -105,6 +107,24 @@ public static void Initialize(bool forceUnityVRMode = false) SteamVR_Behaviour.Initialize(forceUnityVRMode); } + /** + * Initializes SteamVR in standalone mode without + * This mode is intended for overlays that do not use Unity's XR rendering. + */ + public static void InitializeStandalone(EVRApplicationType applicationType, string pchStartupInfo = "") + { + var error = EVRInitError.None; + OpenVR.Init(ref error, applicationType, pchStartupInfo); + if (error != EVRInitError.None) + { + ReportError(error); + } + + isStandalone = true; + + Initialize(false); + } + public static bool usingNativeSupport { get { return XRDevice.GetNativePtr() != System.IntPtr.Zero; } @@ -116,21 +136,24 @@ private static void ReportGeneralErrors() { string errorLog = "[SteamVR] Initialization failed. "; - if (XRSettings.enabled == false) - errorLog += "VR may be disabled in player settings. Go to player settings in the editor and check the 'Virtual Reality Supported' checkbox'. "; - if (XRSettings.supportedDevices != null && XRSettings.supportedDevices.Length > 0) - { - if (XRSettings.supportedDevices.Contains("OpenVR") == false) - errorLog += "OpenVR is not in your list of supported virtual reality SDKs. Add it to the list in player settings. "; - else if (XRSettings.supportedDevices.First().Contains("OpenVR") == false) - errorLog += "OpenVR is not first in your list of supported virtual reality SDKs. This is okay, but if you have an Oculus device plugged in, and Oculus above OpenVR in this list, it will try and use the Oculus SDK instead of OpenVR. "; - } - else + if (!isStandalone) { - errorLog += "You have no SDKs in your Player Settings list of supported virtual reality SDKs. Add OpenVR to it. "; - } + if (XRSettings.enabled == false) + errorLog += "VR may be disabled in player settings. Go to player settings in the editor and check the 'Virtual Reality Supported' checkbox'. "; + if (XRSettings.supportedDevices != null && XRSettings.supportedDevices.Length > 0) + { + if (XRSettings.supportedDevices.Contains("OpenVR") == false) + errorLog += "OpenVR is not in your list of supported virtual reality SDKs. Add it to the list in player settings. "; + else if (XRSettings.supportedDevices.First().Contains("OpenVR") == false) + errorLog += "OpenVR is not first in your list of supported virtual reality SDKs. This is okay, but if you have an Oculus device plugged in, and Oculus above OpenVR in this list, it will try and use the Oculus SDK instead of OpenVR. "; + } + else + { + errorLog += "You have no SDKs in your Player Settings list of supported virtual reality SDKs. Add OpenVR to it. "; + } - errorLog += "To force OpenVR initialization call SteamVR.Initialize(true). "; + errorLog += "To force OpenVR initialization call SteamVR.Initialize(true). "; + } Debug.LogWarning(errorLog); } @@ -142,7 +165,7 @@ private static SteamVR CreateInstance() try { var error = EVRInitError.None; - if (!SteamVR.usingNativeSupport) + if (!SteamVR.usingNativeSupport && !isStandalone) { ReportGeneralErrors(); initializedState = InitializedStates.InitializeFailure;