private static void LoadInstance() { if (_instance == null) { _instance = Resources.Load <SteamVR_Settings>("SteamVR_Settings"); if (_instance == null) { _instance = SteamVR_Settings.CreateInstance <SteamVR_Settings>(); #if UNITY_EDITOR string folderPath = SteamVR.GetResourcesFolderPath(true); string assetPath = System.IO.Path.Combine(folderPath, "SteamVR_Settings.asset"); UnityEditor.AssetDatabase.CreateAsset(_instance, assetPath); UnityEditor.AssetDatabase.SaveAssets(); #endif } if (string.IsNullOrEmpty(_instance.appKey)) { _instance.appKey = SteamVR.GenerateAppKey(); Debug.Log("[SteamVR] Generated you an app key of: " + _instance.appKey + ". This can be changed in Assets/SteamVR/Resources/SteamVR_Settings"); #if UNITY_EDITOR UnityEditor.EditorUtility.SetDirty(_instance); UnityEditor.AssetDatabase.SaveAssets(); #endif } } }
private static void LoadInstance() { if (_instance == null) { _instance = Resources.Load <SteamVR_Settings>("SteamVR_Settings"); if (_instance == null) { _instance = SteamVR_Settings.CreateInstance <SteamVR_Settings>(); #if UNITY_EDITOR //string folderPath = SteamVR.GetResourcesFolderPath(true); string folderPath = "Assets"; string assetPath = System.IO.Path.Combine(folderPath, "SteamVR_Settings.asset"); UnityEditor.AssetDatabase.CreateAsset(_instance, assetPath); UnityEditor.AssetDatabase.SaveAssets(); #endif } if (string.IsNullOrEmpty(_instance.editorAppKey)) { _instance.editorAppKey = SteamVR.GenerateAppKey(); Debug.Log("<b>[SteamVR Setup]</b> Generated you an editor app key of: " + _instance.editorAppKey + ". This lets the editor tell SteamVR what project this is. Has no effect on builds. This can be changed in Assets/SteamVR/Resources/SteamVR_Settings"); #if UNITY_EDITOR UnityEditor.EditorUtility.SetDirty(_instance); UnityEditor.AssetDatabase.SaveAssets(); #endif } } }
public static string GetResourcesFolderPath(bool fromAssetsDirectory = false) { SteamVR_Settings asset = ScriptableObject.CreateInstance <SteamVR_Settings>(); UnityEditor.MonoScript scriptAsset = UnityEditor.MonoScript.FromScriptableObject(asset); string scriptPath = UnityEditor.AssetDatabase.GetAssetPath(scriptAsset); System.IO.FileInfo fi = new System.IO.FileInfo(scriptPath); string rootPath = fi.Directory.Parent.ToString(); string resourcesPath = System.IO.Path.Combine(rootPath, "Resources"); resourcesPath = resourcesPath.Replace("//", "/"); resourcesPath = resourcesPath.Replace("\\\\", "\\"); resourcesPath = resourcesPath.Replace("\\", "/"); if (fromAssetsDirectory) { int assetsIndex = resourcesPath.IndexOf("/Assets/"); resourcesPath = resourcesPath.Substring(assetsIndex + 1); } return(resourcesPath); }
private static void LoadInstance() { if (_instance == null) { _instance = Resources.Load <SteamVR_Settings>("SteamVR_Settings"); if (_instance == null) { _instance = SteamVR_Settings.CreateInstance <SteamVR_Settings>(); } SetDefaultsIfNeeded(); } }
private static void LoadInstance() { if (_instance == null) { _instance = Resources.Load <SteamVR_Settings>("SteamVR_Settings"); if (_instance == null) { _instance = SteamVR_Settings.CreateInstance <SteamVR_Settings>(); #if UNITY_EDITOR string localFolderPath = SteamVR.GetSteamVRResourcesFolderPath(true); string assetPath = System.IO.Path.Combine(localFolderPath, "SteamVR_Settings.asset"); UnityEditor.AssetDatabase.CreateAsset(_instance, assetPath); UnityEditor.AssetDatabase.SaveAssets(); #endif } SetDefaultsIfNeeded(); } }
public static string GetSteamVRFolderPath(bool localToAssetsFolder = false) { SteamVR_Settings asset = ScriptableObject.CreateInstance <SteamVR_Settings>(); MonoScript scriptAsset = MonoScript.FromScriptableObject(asset); string scriptPath = AssetDatabase.GetAssetPath(scriptAsset); FileInfo settingsScriptFileInfo = new FileInfo(scriptPath); string fullPath = settingsScriptFileInfo.Directory.Parent.FullName; if (localToAssetsFolder == false) { return(fullPath); } else { DirectoryInfo assetsDirectoryInfo = new DirectoryInfo(Application.dataPath); string localPath = fullPath.Substring(assetsDirectoryInfo.Parent.FullName.Length + 1); //plus separator char return(localPath); } }
private static SteamVR CreateInstance() { initializedState = InitializedStates.Initializing; try { var error = EVRInitError.None; #if !OPENVR_XR_API if (!SteamVR.usingNativeSupport) { ReportGeneralErrors(); initializedState = InitializedStates.InitializeFailure; SteamVR_Events.Initialized.Send(false); return(null); } #endif // Verify common interfaces are valid. OpenVR.GetGenericInterface(OpenVR.IVRCompositor_Version, ref error); if (error != EVRInitError.None) { initializedState = InitializedStates.InitializeFailure; ReportError(error); ReportGeneralErrors(); SteamVR_Events.Initialized.Send(false); return(null); } OpenVR.GetGenericInterface(OpenVR.IVROverlay_Version, ref error); if (error != EVRInitError.None) { initializedState = InitializedStates.InitializeFailure; ReportError(error); SteamVR_Events.Initialized.Send(false); return(null); } OpenVR.GetGenericInterface(OpenVR.IVRInput_Version, ref error); if (error != EVRInitError.None) { initializedState = InitializedStates.InitializeFailure; ReportError(error); SteamVR_Events.Initialized.Send(false); return(null); } settings = SteamVR_Settings.instance; #if !OPENVR_XR_API if (Application.isEditor) { IdentifyEditorApplication(); } SteamVR_Input.IdentifyActionsFile(); #endif if (SteamVR_Settings.instance.inputUpdateMode != SteamVR_UpdateModes.Nothing || SteamVR_Settings.instance.poseUpdateMode != SteamVR_UpdateModes.Nothing) { SteamVR_Input.Initialize(); #if UNITY_EDITOR if (SteamVR_Input.IsOpeningSetup()) { return(null); } #endif } } catch (System.Exception e) { Debug.LogError("<b>[SteamVR]</b> " + e); SteamVR_Events.Initialized.Send(false); return(null); } _enabled = true; initializedState = InitializedStates.InitializeSuccess; SteamVR_Events.Initialized.Send(true); return(new SteamVR()); }
private static SteamVR CreateInstance() { try { var error = EVRInitError.None; if (!SteamVR.usingNativeSupport) { 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.Contains("OpenVR") == false) { errorLog += "OpenVR is not in your list of supported virtual reality SDKs. Add it to the list in player settings. "; } errorLog += "To force OpenVR initialization call SteamVR.Initialize(true). "; Debug.Log(errorLog); SteamVR_Events.Initialized.Send(false); return(null); } // Verify common interfaces are valid. OpenVR.GetGenericInterface(OpenVR.IVRCompositor_Version, ref error); if (error != EVRInitError.None) { ReportError(error); SteamVR_Events.Initialized.Send(false); return(null); } OpenVR.GetGenericInterface(OpenVR.IVROverlay_Version, ref error); if (error != EVRInitError.None) { ReportError(error); SteamVR_Events.Initialized.Send(false); return(null); } settings = SteamVR_Settings.instance; SteamVR_Input.PreInitialize(); IdentifyApplication(); SteamVR_Input.IdentifyActionsFile(); if (SteamVR_Settings.instance.inputUpdateMode != SteamVR_UpdateModes.Nothing || SteamVR_Settings.instance.poseUpdateMode != SteamVR_UpdateModes.Nothing) { SteamVR_Input.Initialize(); } } catch (System.Exception e) { Debug.LogError(e); SteamVR_Events.Initialized.Send(false); return(null); } _enabled = true; SteamVR_Events.Initialized.Send(true); return(new SteamVR()); }
public static void Update() { if (!SteamVR_Settings.instance.autoEnableVR || Application.isPlaying) { End(); } if (UnityEditor.PlayerSettings.virtualRealitySupported == false) { if (forceInstall == false) { int shouldInstall = UnityEditor.EditorUtility.DisplayDialogComplex("SteamVR", "Would you like to enable Virtual Reality mode?\n\nThis will install the OpenVR for Desktop package and enable it in Player Settings.", "Yes", "No, and don't ask again", "No"); switch (shouldInstall) { case 0: //yes UnityEditor.PlayerSettings.virtualRealitySupported = true; break; case 1: //no End(); return; case 2: //no, don't ask SteamVR_Settings.instance.autoEnableVR = false; SteamVR_Settings.Save(); End(); return; } } Debug.Log("<b>[SteamVR Setup]</b> Enabled virtual reality support in Player Settings. (you can disable this by unchecking Assets/SteamVR/SteamVR_Settings.autoEnableVR)"); } switch (updateState) { case PackageStates.None: //see if we have the package listRequest = UnityEditor.PackageManager.Client.List(true); updateState = PackageStates.WaitingForList; break; case PackageStates.WaitingForList: if (listRequest == null) { listRequest = UnityEditor.PackageManager.Client.List(true); updateState = PackageStates.WaitingForList; } else if (listRequest.IsCompleted) { if (listRequest.Error != null || listRequest.Status == UnityEditor.PackageManager.StatusCode.Failure) { updateState = PackageStates.Failed; break; } string packageName = unityOpenVRPackageString; bool hasPackage = listRequest.Result.Any(package => package.name == packageName); if (hasPackage == false) { //if we don't have the package - then install it addRequest = UnityEditor.PackageManager.Client.Add(packageName); updateState = PackageStates.WaitingForAdd; addTryCount++; Debug.Log("<b>[SteamVR Setup]</b> Installing OpenVR package..."); addingPackageTime.Start(); addingPackageTimeTotal.Start(); } else { //if we do have the package, make sure it's enabled. updateState = PackageStates.Installed; //already installed } } break; case PackageStates.WaitingForAdd: if (addRequest.IsCompleted) { if (addRequest.Error != null || addRequest.Status == UnityEditor.PackageManager.StatusCode.Failure) { updateState = PackageStates.Failed; break; } else { //if the package manager says we added it then confirm that with the list listRequest = UnityEditor.PackageManager.Client.List(true); updateState = PackageStates.WaitingForAddConfirm; } } else { if (addingPackageTimeTotal.Elapsed.TotalSeconds > estimatedTimeToInstall) { if (addTryCount == 1) { estimatedTimeToInstall *= 2; //give us more time to retry } else { updateState = PackageStates.Failed; } } string dialogText; if (addTryCount == 1) { dialogText = "Installing OpenVR from Unity Package Manager..."; } else { dialogText = "Retrying OpenVR install from Unity Package Manager..."; } bool cancel = UnityEditor.EditorUtility.DisplayCancelableProgressBar("SteamVR", dialogText, (float)addingPackageTimeTotal.Elapsed.TotalSeconds / estimatedTimeToInstall); if (cancel) { updateState = PackageStates.Failed; } if (addingPackageTime.Elapsed.TotalSeconds > 10) { Debug.Log("<b>[SteamVR Setup]</b> Waiting for package manager to install OpenVR package..."); addingPackageTime.Stop(); addingPackageTime.Reset(); addingPackageTime.Start(); } } break; case PackageStates.WaitingForAddConfirm: if (listRequest.IsCompleted) { if (listRequest.Error != null) { updateState = PackageStates.Failed; break; } string packageName = unityOpenVRPackageString; bool hasPackage = listRequest.Result.Any(package => package.name == packageName); if (hasPackage == false) { if (addTryCount == 1) { addRequest = UnityEditor.PackageManager.Client.Add(packageName); updateState = PackageStates.WaitingForAdd; addTryCount++; Debug.Log("<b>[SteamVR Setup]</b> Retrying OpenVR package install..."); } else { updateState = PackageStates.Failed; } } else { updateState = PackageStates.Installed; //installed successfully Debug.Log("<b>[SteamVR Setup]</b> Successfully installed OpenVR Desktop package."); } } break; case PackageStates.Installed: UnityEditor.BuildTargetGroup currentTarget = UnityEditor.EditorUserBuildSettings.selectedBuildTargetGroup; string[] devices = UnityEditorInternal.VR.VREditor.GetVREnabledDevicesOnTargetGroup(currentTarget); bool hasOpenVR = false; bool isFirst = false; if (devices.Length != 0) { int index = Array.FindIndex(devices, device => string.Equals(device, openVRString, System.StringComparison.CurrentCultureIgnoreCase)); hasOpenVR = index != -1; isFirst = index == 0; } //list openvr as the first option if it was in the list already List <string> devicesList = new List <string>(devices); if (isFirst == false) { if (hasOpenVR == true) { devicesList.Remove(openVRString); } devicesList.Insert(0, openVRString); string[] newDevices = devicesList.ToArray(); UnityEditorInternal.VR.VREditor.SetVREnabledDevicesOnTargetGroup(currentTarget, newDevices); Debug.Log("<b>[SteamVR Setup]</b> Added OpenVR to supported VR SDKs list."); } End(); break; case PackageStates.Failed: End(); string failtext = "The Unity Package Manager failed to automatically install the OpenVR Desktop package. Please open the Package Manager Window and try to install it manually."; UnityEditor.EditorUtility.DisplayDialog("SteamVR", failtext, "Ok"); Debug.Log("<b>[SteamVR Setup]</b> " + failtext); break; } }
private static SteamVR CreateInstance() { SteamVR.initializedState = SteamVR.InitializedStates.Initializing; try { EVRInitError evrinitError = EVRInitError.None; OpenVR.GetGenericInterface("IVRCompositor_022", ref evrinitError); OpenVR.Init(ref evrinitError, EVRApplicationType.VRApplication_Scene, ""); CVRSystem system = OpenVR.System; string manifestFile = SteamVR.GetManifestFile(); EVRApplicationError evrapplicationError = OpenVR.Applications.AddApplicationManifest(manifestFile, true); if (evrapplicationError != EVRApplicationError.None) { UnityEngine.Debug.LogError("<b>[SteamVR_Standalone]</b> Error adding vr manifest file: " + evrapplicationError.ToString()); } int id = Process.GetCurrentProcess().Id; OpenVR.Applications.IdentifyApplication((uint)id, SteamVR_Settings.instance.editorAppKey); UnityEngine.Debug.Log("Is HMD here? " + OpenVR.IsHmdPresent().ToString()); if (evrinitError != EVRInitError.None) { SteamVR.initializedState = SteamVR.InitializedStates.InitializeFailure; SteamVR.ReportError(evrinitError); SteamVR.ReportGeneralErrors(); SteamVR_Events.Initializing.Send(false); return(null); } OpenVR.GetGenericInterface("IVROverlay_021", ref evrinitError); if (evrinitError != EVRInitError.None) { SteamVR.initializedState = SteamVR.InitializedStates.InitializeFailure; SteamVR.ReportError(evrinitError); SteamVR_Events.Initializing.Send(false); return(null); } OpenVR.GetGenericInterface("IVRInput_007", ref evrinitError); if (evrinitError != EVRInitError.None) { SteamVR.initializedState = SteamVR.InitializedStates.InitializeFailure; SteamVR.ReportError(evrinitError); SteamVR_Events.Initializing.Send(false); return(null); } SteamVR.settings = SteamVR_Settings.instance; if (Application.isEditor) { SteamVR.IdentifyEditorApplication(true); } SteamVR_Input.IdentifyActionsFile(true); if (SteamVR_Settings.instance.inputUpdateMode != SteamVR_UpdateModes.Nothing || SteamVR_Settings.instance.poseUpdateMode != SteamVR_UpdateModes.Nothing) { SteamVR_Input.Initialize(false); } } catch (Exception arg) { UnityEngine.Debug.LogError("<b>[SteamVR_Standalone]</b> " + arg); SteamVR_Events.Initializing.Send(false); return(null); } SteamVR._enabled = true; SteamVR.initializedState = SteamVR.InitializedStates.InitializeSuccess; SteamVR_Events.Initializing.Send(true); return(new SteamVR()); }
static void Update() { bool show = (!EditorPrefs.HasKey(ignore + buildTarget) && EditorUserBuildSettings.activeBuildTarget != recommended_BuildTarget) || (!EditorPrefs.HasKey(ignore + showUnitySplashScreen) && #if (UNITY_5_4 || UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0) PlayerSettings.showUnitySplashScreen != recommended_ShowUnitySplashScreen) || #else PlayerSettings.SplashScreen.show != recommended_ShowUnitySplashScreen) || #endif #if UNITY_2018_1_OR_NEWER (!EditorPrefs.HasKey(ignore + defaultIsFullScreen) && PlayerSettings.fullScreenMode != recommended_FullScreenMode) || #else (!EditorPrefs.HasKey(ignore + defaultIsFullScreen) && PlayerSettings.defaultIsFullScreen != recommended_DefaultIsFullScreen) || (!EditorPrefs.HasKey(ignore + fullscreenMode) && PlayerSettings.d3d11FullscreenMode != recommended_FullscreenMode) || #endif (!EditorPrefs.HasKey(ignore + defaultScreenSize) && (PlayerSettings.defaultScreenWidth != recommended_DefaultScreenWidth || PlayerSettings.defaultScreenHeight != recommended_DefaultScreenHeight)) || (!EditorPrefs.HasKey(ignore + runInBackground) && PlayerSettings.runInBackground != recommended_RunInBackground) || (!EditorPrefs.HasKey(ignore + displayResolutionDialog) && PlayerSettings.displayResolutionDialog != recommended_DisplayResolutionDialog) || (!EditorPrefs.HasKey(ignore + resizableWindow) && PlayerSettings.resizableWindow != recommended_ResizableWindow) || (!EditorPrefs.HasKey(ignore + visibleInBackground) && PlayerSettings.visibleInBackground != recommended_VisibleInBackground) || #if (UNITY_5_4 || UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0) (!EditorPrefs.HasKey(ignore + renderingPath) && PlayerSettings.renderingPath != recommended_RenderPath) || #endif (!EditorPrefs.HasKey(ignore + colorSpace) && PlayerSettings.colorSpace != recommended_ColorSpace) || (!EditorPrefs.HasKey(ignore + gpuSkinning) && PlayerSettings.gpuSkinning != recommended_GpuSkinning) || #if false (!EditorPrefs.HasKey(ignore + singlePassStereoRendering) && PlayerSettings.singlePassStereoRendering != recommended_SinglePassStereoRendering) || #endif forceShow; if (show) { window = GetWindow <SteamVR_UnitySettingsWindow>(true); window.minSize = new Vector2(320, 440); //window.title = "SteamVR"; } SteamVR_Settings.AutoEnableVR(); var dlls = new string[] { "Plugins/x86/openvr_api.dll", "Plugins/x86_64/openvr_api.dll" }; foreach (var path in dlls) { if (!File.Exists(Application.dataPath + "/" + path)) { continue; } if (AssetDatabase.DeleteAsset("Assets/" + path)) { Debug.Log("<b>[SteamVR]</b> Deleting " + path); } else { Debug.Log("<b>[SteamVR]</b> " + path + " in use; cannot delete. Please restart Unity to complete upgrade."); } } EditorApplication.update -= Update; }
public static void Update() { if (!SteamVR_Settings.instance.autoEnableVR || Application.isPlaying) { End(); } bool enabledVR = false; int shouldInstall = -1; if (UnityEditor.PlayerSettings.virtualRealitySupported == false) { shouldInstall = UnityEditor.EditorUtility.DisplayDialogComplex("SteamVR", "Would you like to enable Virtual Reality mode?\n\nThis will enable Virtual Reality in Player Settings and add OpenVR as a target.", "Yes", "No, and don't ask again", "No"); switch (shouldInstall) { case 0: //yes UnityEditor.PlayerSettings.virtualRealitySupported = true; break; case 1: //no: UnityEditor.EditorApplication.update -= Update; return; case 2: //no, don't ask SteamVR_Settings.instance.autoEnableVR = false; SteamVR_Settings.Save(); UnityEditor.EditorApplication.update -= Update; return; } } UnityEditor.BuildTargetGroup currentTarget = UnityEditor.EditorUserBuildSettings.selectedBuildTargetGroup; #if UNITY_5_6_OR_NEWER string[] devices = UnityEditorInternal.VR.VREditor.GetVREnabledDevicesOnTargetGroup(currentTarget); #else string[] devices = UnityEditorInternal.VR.VREditor.GetVREnabledDevices(currentTarget); #endif bool hasOpenVR = devices.Any(device => string.Equals(device, openVRString, System.StringComparison.CurrentCultureIgnoreCase)); if (hasOpenVR == false || enabledVR) { string[] newDevices; if (enabledVR && hasOpenVR == false) { newDevices = new string[] { openVRString }; //only list openvr if we enabled it } else { List <string> devicesList = new List <string>(devices); //list openvr as the first option if it wasn't in the list. if (hasOpenVR) { devicesList.Remove(openVRString); } devicesList.Insert(0, openVRString); newDevices = devicesList.ToArray(); } int shouldEnable = -1; if (shouldInstall == 0) { shouldEnable = 0; } else { shouldEnable = UnityEditor.EditorUtility.DisplayDialogComplex("SteamVR", "Would you like to enable OpenVR as a VR target?", "Yes", "No, and don't ask again", "No"); } switch (shouldEnable) { case 0: //yes #if UNITY_5_6_OR_NEWER UnityEditorInternal.VR.VREditor.SetVREnabledDevicesOnTargetGroup(currentTarget, newDevices); #else UnityEditorInternal.VR.VREditor.SetVREnabledDevices(currentTarget, newDevices); #endif Debug.Log("<b>[SteamVR Setup]</b> Added OpenVR to supported VR SDKs list."); break; case 1: //no: break; case 2: //no, don't ask SteamVR_Settings.instance.autoEnableVR = false; SteamVR_Settings.Save(); break; } } UnityEditor.EditorApplication.update -= Update; }