Skip to content

Allow SteamVR Unity Plugin to run in "Standalone" mode without Unity XR enabled #336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 38 additions & 15 deletions Assets/SteamVR/Scripts/SteamVR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static bool enabled
{
get
{
if (!XRSettings.enabled)
if (!XRSettings.enabled && !isStandalone)
enabled = false;
return _enabled;
}
Expand Down Expand Up @@ -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)
Expand All @@ -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; }
Expand All @@ -116,21 +136,24 @@ private static void ReportGeneralErrors()
{
string errorLog = "<b>[SteamVR]</b> 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. <b>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.</b> ";
}
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. <b>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.</b> ";
}
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);
}
Expand All @@ -142,7 +165,7 @@ private static SteamVR CreateInstance()
try
{
var error = EVRInitError.None;
if (!SteamVR.usingNativeSupport)
if (!SteamVR.usingNativeSupport && !isStandalone)
{
ReportGeneralErrors();
initializedState = InitializedStates.InitializeFailure;
Expand Down