SteamVR_Settings.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //======= Copyright (c) Valve Corporation, All rights reserved. ===============
  2. using UnityEngine;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. namespace Valve.VR
  7. {
  8. public class SteamVR_Settings : ScriptableObject
  9. {
  10. private static SteamVR_Settings _instance;
  11. public static SteamVR_Settings instance
  12. {
  13. get
  14. {
  15. LoadInstance();
  16. return _instance;
  17. }
  18. }
  19. public bool pauseGameWhenDashboardVisible = true;
  20. public bool lockPhysicsUpdateRateToRenderFrequency = true;
  21. public Valve.VR.ETrackingUniverseOrigin trackingSpace = Valve.VR.ETrackingUniverseOrigin.TrackingUniverseStanding;
  22. [Tooltip("Filename local to the project root (or executable, in a build)")]
  23. public string actionsFilePath = "actions.json";
  24. [Tooltip("Path local to the Assets folder")]
  25. public string steamVRInputPath = "SteamVR_Input";
  26. public SteamVR_UpdateModes inputUpdateMode = SteamVR_UpdateModes.OnUpdate;
  27. public SteamVR_UpdateModes poseUpdateMode = SteamVR_UpdateModes.OnPreCull;
  28. public bool activateFirstActionSetOnStart = true;
  29. [Tooltip("This is the app key the unity editor will use to identify your application. (can be \"steam.app.[appid]\" to persist bindings between editor steam)")]
  30. public string editorAppKey;
  31. [Tooltip("The SteamVR Plugin can automatically make sure VR is enabled in your player settings and if not, enable it.")]
  32. public bool autoEnableVR = true;
  33. public bool IsInputUpdateMode(SteamVR_UpdateModes tocheck)
  34. {
  35. return (inputUpdateMode & tocheck) == tocheck;
  36. }
  37. public bool IsPoseUpdateMode(SteamVR_UpdateModes tocheck)
  38. {
  39. return (poseUpdateMode & tocheck) == tocheck;
  40. }
  41. public static void VerifyScriptableObject()
  42. {
  43. LoadInstance();
  44. }
  45. private static void LoadInstance()
  46. {
  47. if (_instance == null)
  48. {
  49. _instance = Resources.Load<SteamVR_Settings>("SteamVR_Settings");
  50. if (_instance == null)
  51. {
  52. _instance = SteamVR_Settings.CreateInstance<SteamVR_Settings>();
  53. #if UNITY_EDITOR
  54. string folderPath = SteamVR.GetResourcesFolderPath(true);
  55. string assetPath = System.IO.Path.Combine(folderPath, "SteamVR_Settings.asset");
  56. UnityEditor.AssetDatabase.CreateAsset(_instance, assetPath);
  57. UnityEditor.AssetDatabase.SaveAssets();
  58. #endif
  59. }
  60. if (string.IsNullOrEmpty(_instance.editorAppKey))
  61. {
  62. _instance.editorAppKey = SteamVR.GenerateAppKey();
  63. 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");
  64. #if UNITY_EDITOR
  65. UnityEditor.EditorUtility.SetDirty(_instance);
  66. UnityEditor.AssetDatabase.SaveAssets();
  67. #endif
  68. }
  69. }
  70. }
  71. }
  72. }