OVRProjectConfig.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /************************************************************************************
  2. Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
  3. Licensed under the Oculus SDK License Version 3.4.1 (the "License");
  4. you may not use the Oculus SDK except in compliance with the License,
  5. which is provided at the time of installation or download, or which
  6. otherwise accompanies this software in either electronic or hard copy form.
  7. You may obtain a copy of the License at
  8. https://developer.oculus.com/licenses/sdk-3.4.1
  9. Unless required by applicable law or agreed to in writing, the Oculus SDK
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ************************************************************************************/
  15. using System.Collections;
  16. using System.Collections.Generic;
  17. using UnityEngine;
  18. using UnityEditor;
  19. using System.IO;
  20. using System;
  21. [System.Serializable]
  22. public class OVRProjectConfig : ScriptableObject
  23. {
  24. public enum DeviceType
  25. {
  26. GearVrOrGo = 0,
  27. Quest = 1
  28. }
  29. public enum HandTrackingSupport
  30. {
  31. ControllersOnly = 0,
  32. ControllersAndHands = 1,
  33. HandsOnly = 2
  34. }
  35. public List<DeviceType> targetDeviceTypes;
  36. public HandTrackingSupport handTrackingSupport;
  37. public bool disableBackups;
  38. public bool enableNSCConfig;
  39. //public const string OculusProjectConfigAssetPath = "Assets/Oculus/OculusProjectConfig.asset";
  40. private static string GetOculusProjectConfigAssetPath()
  41. {
  42. var so = ScriptableObject.CreateInstance(typeof(OVRPluginUpdaterStub));
  43. var script = MonoScript.FromScriptableObject(so);
  44. string assetPath = AssetDatabase.GetAssetPath(script);
  45. string editorDir = Directory.GetParent(assetPath).FullName;
  46. string ovrDir = Directory.GetParent(editorDir).FullName;
  47. string oculusDir = Directory.GetParent(ovrDir).FullName;
  48. string configAssetPath = Path.GetFullPath(Path.Combine(oculusDir, "OculusProjectConfig.asset"));
  49. Uri configUri = new Uri(configAssetPath);
  50. Uri projectUri = new Uri(Application.dataPath);
  51. Uri relativeUri = projectUri.MakeRelativeUri(configUri);
  52. return relativeUri.ToString();
  53. }
  54. public static OVRProjectConfig GetProjectConfig()
  55. {
  56. OVRProjectConfig projectConfig = null;
  57. string oculusProjectConfigAssetPath = GetOculusProjectConfigAssetPath();
  58. try
  59. {
  60. projectConfig = AssetDatabase.LoadAssetAtPath(oculusProjectConfigAssetPath, typeof(OVRProjectConfig)) as OVRProjectConfig;
  61. }
  62. catch (System.Exception e)
  63. {
  64. Debug.LogWarningFormat("Unable to load ProjectConfig from {0}, error {1}", oculusProjectConfigAssetPath, e.Message);
  65. }
  66. if (projectConfig == null)
  67. {
  68. projectConfig = ScriptableObject.CreateInstance<OVRProjectConfig>();
  69. projectConfig.targetDeviceTypes = new List<DeviceType>();
  70. projectConfig.targetDeviceTypes.Add(DeviceType.Quest);
  71. projectConfig.handTrackingSupport = HandTrackingSupport.ControllersOnly;
  72. projectConfig.disableBackups = true;
  73. projectConfig.enableNSCConfig = true;
  74. AssetDatabase.CreateAsset(projectConfig, oculusProjectConfigAssetPath);
  75. }
  76. return projectConfig;
  77. }
  78. public static void CommitProjectConfig(OVRProjectConfig projectConfig)
  79. {
  80. string oculusProjectConfigAssetPath = GetOculusProjectConfigAssetPath();
  81. if (AssetDatabase.GetAssetPath(projectConfig) != oculusProjectConfigAssetPath)
  82. {
  83. Debug.LogWarningFormat("The asset path of ProjectConfig is wrong. Expect {0}, get {1}", oculusProjectConfigAssetPath, AssetDatabase.GetAssetPath(projectConfig));
  84. }
  85. EditorUtility.SetDirty(projectConfig);
  86. }
  87. }