public void InitializeActionManifestFileRelativeFilePath() { if (IsLegacy) { ActionManifestFileRelativeFilePath = System.IO.Path.Combine(OpenVRSettings.GetStreamingSteamVRPath(false), OpenVRSettings.ActionManifestFileName); } }
public bool InitializeActionManifestFileRelativeFilePath() { string oldPath = ActionManifestFileRelativeFilePath; string newPath; if (OpenVRHelpers.IsUsingSteamVRInput()) { newPath = System.IO.Path.Combine(OpenVRSettings.GetStreamingSteamVRPath(false), OpenVRHelpers.GetActionManifestNameFromPlugin()); string fullpath = System.IO.Path.GetFullPath("."); newPath = newPath.Remove(0, fullpath.Length + 1); if (newPath.StartsWith("Assets")) { newPath = newPath.Remove(0, "Assets".Length + 1); } } else { newPath = null; } #if UNITY_EDITOR if (newPath != oldPath) { ActionManifestFileRelativeFilePath = newPath; UnityEditor.EditorUtility.SetDirty(this); UnityEditor.AssetDatabase.SaveAssets(); return(true); } #endif return(false); }
public override bool Initialize() { #if UNITY_INPUT_SYSTEM //InputLayoutLoader.RegisterInputLayouts(); #endif //this only works at the right time in editor. In builds we use a different method (reading the asset manually) #if UNITY_EDITOR OpenVRSettings settings = OpenVRSettings.GetSettings(); if (settings != null) { if (string.IsNullOrEmpty(settings.EditorAppKey)) { settings.EditorAppKey = settings.GenerateEditorAppKey(); } UserDefinedSettings userDefinedSettings; userDefinedSettings.stereoRenderingMode = (ushort)settings.GetStereoRenderingMode(); userDefinedSettings.initializationType = (ushort)settings.GetInitializationType(); userDefinedSettings.applicationName = null; userDefinedSettings.editorAppKey = null; userDefinedSettings.mirrorViewMode = (ushort)settings.GetMirrorViewMode(); userDefinedSettings.editorAppKey = settings.EditorAppKey; //only set the key if we're in the editor. Otherwise let steamvr set the key. if (OpenVRHelpers.IsUsingSteamVRInput()) { userDefinedSettings.editorAppKey = OpenVRHelpers.GetEditorAppKeyFromPlugin(); } userDefinedSettings.applicationName = string.Format("[Testing] {0}", GetEscapedApplicationName()); settings.InitializeActionManifestFileRelativeFilePath(); userDefinedSettings.actionManifestPath = settings.ActionManifestFileRelativeFilePath; SetUserDefinedSettings(userDefinedSettings); } #endif CreateSubsystem <XRDisplaySubsystemDescriptor, XRDisplaySubsystem>(s_DisplaySubsystemDescriptors, "OpenVR Display"); EVRInitError result = GetInitializationResult(); if (result != EVRInitError.None) { DestroySubsystem <XRDisplaySubsystem>(); Debug.LogError("<b>[OpenVR]</b> Could not initialize OpenVR. Error code: " + result.ToString()); return(false); } CreateSubsystem <XRInputSubsystemDescriptor, XRInputSubsystem>(s_InputSubsystemDescriptors, "OpenVR Input"); OpenVREvents.Initialize(); TickCallbackDelegate callback = TickCallback; RegisterTickCallback(callback); callback(0); return(displaySubsystem != null && inputSubsystem != null); }
public override bool Initialize() { Debug.Log("Initialize openvr loader"); #if UNITY_INPUT_SYSTEM InputLayoutLoader.RegisterInputLayouts(); #endif OpenVRSettings settings = OpenVRSettings.GetSettings(); if (settings != null) { if (string.IsNullOrEmpty(settings.EditorAppKey)) { settings.EditorAppKey = settings.GenerateEditorAppKey(); } UserDefinedSettings userDefinedSettings; userDefinedSettings.stereoRenderingMode = (ushort)settings.GetStereoRenderingMode(); userDefinedSettings.initializationType = (ushort)settings.GetInitializationType(); userDefinedSettings.applicationName = null; userDefinedSettings.editorAppKey = null; userDefinedSettings.isSteamVRLegacyInput = settings.IsLegacy; userDefinedSettings.mirrorViewMode = (ushort)settings.GetMirrorViewMode(); //todo: determine legacy state? #if UNITY_EDITOR userDefinedSettings.editorAppKey = settings.EditorAppKey; //only set the key if we're in the editor. Otherwise let steamvr set the key. userDefinedSettings.applicationName = string.Format("[Testing] {0}", GetEscapedApplicationName()); settings.InitializeActionManifestFileRelativeFilePath(); #endif //only set the path if the file exists FileInfo actionManifestFileInfo = new FileInfo(settings.ActionManifestFileRelativeFilePath); if (actionManifestFileInfo.Exists) { userDefinedSettings.actionManifestPath = actionManifestFileInfo.FullName.Replace("\\", "\\\\"); } else { userDefinedSettings.actionManifestPath = null; } SetUserDefinedSettings(userDefinedSettings); } CreateSubsystem <XRDisplaySubsystemDescriptor, XRDisplaySubsystem>(s_DisplaySubsystemDescriptors, "OpenVR Display"); CreateSubsystem <XRInputSubsystemDescriptor, XRInputSubsystem>(s_InputSubsystemDescriptors, "OpenVR Input"); Debug.Log(displaySubsystem); Debug.Log(inputSubsystem); return(displaySubsystem != null && inputSubsystem != null); }
public static OpenVRSettings GetSettings(bool create = true) { OpenVRSettings settings = null; #if UNITY_EDITOR UnityEditor.EditorBuildSettings.TryGetConfigObject <OpenVRSettings>("Unity.XR.OpenVR.Settings", out settings); #else settings = OpenVRSettings.s_Settings; #endif if (settings == null && create) { settings = OpenVRSettings.CreateInstance <OpenVRSettings>(); } return(settings); }
/// This allows end users to switch mirror view modes at runtime with a file. /// To use place a file called openvr_mirrorview.cfg in the same directory as the executable (or root of project). /// The file should be one line with the following key/value: /// MirrorViewMode=openvr /// Acceptable values are left, right, none, and openvr. OpenVR mode is in beta but will show overlays and chaperone bounds. private void ReadMirrorModeConfig() { try { var lines = System.IO.File.ReadAllLines(mirrorViewPath); foreach (var line in lines) { var split = line.Split('='); if (split.Length == 2) { var key = split[0]; if (key == "MirrorViewMode") { string stringMode = split[1]; OpenVRSettings.MirrorViewModes mode = OpenVRSettings.MirrorViewModes.None; if (stringMode.Equals("left", System.StringComparison.CurrentCultureIgnoreCase)) { mode = OpenVRSettings.MirrorViewModes.Left; } else if (stringMode.Equals("right", System.StringComparison.CurrentCultureIgnoreCase)) { mode = OpenVRSettings.MirrorViewModes.Right; } else if (stringMode.Equals("openvr", System.StringComparison.CurrentCultureIgnoreCase)) { mode = OpenVRSettings.MirrorViewModes.OpenVR; } else if (stringMode.Equals("none", System.StringComparison.CurrentCultureIgnoreCase)) { mode = OpenVRSettings.MirrorViewModes.None; } else { Debug.LogError("<b>[OpenVR]</b> Invalid mode specified in openvr_mirrorview.cfg. Options are: Left, Right, None, and OpenVR."); } Debug.Log("<b>[OpenVR]</b> Mirror View Mode changed via file to: " + mode.ToString()); OpenVRSettings.SetMirrorViewMode((ushort)mode); //bypass the local set. } } } } catch { } }
public override bool Start() { WatchForReload(); StartSubsystem <XRDisplaySubsystem>(); StartSubsystem <XRInputSubsystem>(); EVRInitError result = GetInitializationResult(); if (result != EVRInitError.None) { Debug.LogError("<b>[OpenVR]</b> Could not initialize OpenVR. Error code: " + result.ToString()); return(false); } #if !UNITY_METRO try { settings = OpenVRSettings.GetSettings(); // Listen for changes in the mirror mode file if (watcher == null) { var fi = new System.IO.FileInfo(mirrorViewPath); watcher = new System.IO.FileSystemWatcher(fi.DirectoryName, fi.Name); watcher.NotifyFilter = System.IO.NotifyFilters.LastWrite; watcher.Created += OnChanged; watcher.Changed += OnChanged; watcher.EnableRaisingEvents = true; if (fi.Exists) { OnChanged(null, null); } } } catch {} #endif return(true); }
public bool InitializeActionManifestFileRelativeFilePath() { string temp = ActionManifestFileRelativeFilePath; if (IsLegacy) { ActionManifestFileRelativeFilePath = System.IO.Path.Combine(OpenVRSettings.GetStreamingSteamVRPath(false), OpenVRSettings.ActionManifestFileName); } else { ActionManifestFileRelativeFilePath = System.IO.Path.Combine(OpenVRSettings.GetStreamingSteamVRPath(false), OpenVRHelpers.GetActionManifestNameFromPlugin()); } #if UNITY_EDITOR if (temp != ActionManifestFileRelativeFilePath) { UnityEditor.EditorUtility.SetDirty(this); UnityEditor.AssetDatabase.SaveAssets(); return(true); } #endif return(false); }
private void SetupFileSystemWatcher() { try { settings = OpenVRSettings.GetSettings(); // Listen for changes in the mirror mode file if (watcher == null && running) { watcherFile = new System.IO.FileInfo(mirrorViewPath); watcher = new System.IO.FileSystemWatcher(watcherFile.DirectoryName, watcherFile.Name); watcher.NotifyFilter = System.IO.NotifyFilters.LastWrite; watcher.Created += OnChanged; watcher.Changed += OnChanged; watcher.EnableRaisingEvents = true; if (watcherFile.Exists) { OnChanged(null, null); } } } catch { } }
public override bool Initialize() { #if UNITY_INPUT_SYSTEM InputLayoutLoader.RegisterInputLayouts(); #endif //this only works at the right time in editor. In builds we use a different method (reading the asset manually) #if UNITY_EDITOR OpenVRSettings settings = OpenVRSettings.GetSettings(); if (settings != null) { if (string.IsNullOrEmpty(settings.EditorAppKey)) { settings.EditorAppKey = settings.GenerateEditorAppKey(); } UserDefinedSettings userDefinedSettings; userDefinedSettings.stereoRenderingMode = (ushort)settings.GetStereoRenderingMode(); userDefinedSettings.initializationType = (ushort)settings.GetInitializationType(); userDefinedSettings.applicationName = null; userDefinedSettings.editorAppKey = null; userDefinedSettings.isSteamVRLegacyInput = settings.IsLegacy; userDefinedSettings.mirrorViewMode = (ushort)settings.GetMirrorViewMode(); if (OpenVRHelpers.IsUsingSteamVRInput()) { userDefinedSettings.isSteamVRLegacyInput = false; settings.IsLegacy = false; } userDefinedSettings.editorAppKey = settings.EditorAppKey; //only set the key if we're in the editor. Otherwise let steamvr set the key. if (OpenVRHelpers.IsUsingSteamVRInput()) { userDefinedSettings.editorAppKey = OpenVRHelpers.GetEditorAppKeyFromPlugin(); } userDefinedSettings.applicationName = string.Format("[Testing] {0}", GetEscapedApplicationName()); settings.InitializeActionManifestFileRelativeFilePath(); userDefinedSettings.actionManifestPath = settings.ActionManifestFileRelativeFilePath; //only set the path if the file exists FileInfo actionManifestFileInfo = new FileInfo(userDefinedSettings.actionManifestPath); if (actionManifestFileInfo.Exists) { userDefinedSettings.actionManifestPath = actionManifestFileInfo.FullName.Replace("\\", "\\\\"); } else { userDefinedSettings.actionManifestPath = null; } SetUserDefinedSettings(userDefinedSettings); } #endif CreateSubsystem <XRDisplaySubsystemDescriptor, XRDisplaySubsystem>(s_DisplaySubsystemDescriptors, "OpenVR Display"); CreateSubsystem <XRInputSubsystemDescriptor, XRInputSubsystem>(s_InputSubsystemDescriptors, "OpenVR Input"); OpenVREvents.Initialize(); TickCallbackDelegate callback = TickCallback; RegisterTickCallback(callback); callback(0); return(displaySubsystem != null && inputSubsystem != null); }
public void Awake() { s_Settings = this; }