Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
4.1 KiB

  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 enum ColorGamut
  36. {
  37. Default = 0,
  38. Rec709 = 1,
  39. DciP3 = 2,
  40. Adobe = 3,
  41. Rec2020 = 4
  42. }
  43. public List<DeviceType> targetDeviceTypes;
  44. public HandTrackingSupport handTrackingSupport;
  45. public ColorGamut colorGamut;
  46. public bool disableBackups;
  47. public bool enableNSCConfig;
  48. public bool focusAware;
  49. //public const string OculusProjectConfigAssetPath = "Assets/Oculus/OculusProjectConfig.asset";
  50. private static string GetOculusProjectConfigAssetPath()
  51. {
  52. var so = ScriptableObject.CreateInstance(typeof(OVRPluginUpdaterStub));
  53. var script = MonoScript.FromScriptableObject(so);
  54. string assetPath = AssetDatabase.GetAssetPath(script);
  55. string editorDir = Directory.GetParent(assetPath).FullName;
  56. string ovrDir = Directory.GetParent(editorDir).FullName;
  57. string oculusDir = Directory.GetParent(ovrDir).FullName;
  58. string configAssetPath = Path.GetFullPath(Path.Combine(oculusDir, "OculusProjectConfig.asset"));
  59. Uri configUri = new Uri(configAssetPath);
  60. Uri projectUri = new Uri(Application.dataPath);
  61. Uri relativeUri = projectUri.MakeRelativeUri(configUri);
  62. return relativeUri.ToString();
  63. }
  64. public static OVRProjectConfig GetProjectConfig()
  65. {
  66. OVRProjectConfig projectConfig = null;
  67. string oculusProjectConfigAssetPath = GetOculusProjectConfigAssetPath();
  68. try
  69. {
  70. projectConfig = AssetDatabase.LoadAssetAtPath(oculusProjectConfigAssetPath, typeof(OVRProjectConfig)) as OVRProjectConfig;
  71. }
  72. catch (System.Exception e)
  73. {
  74. Debug.LogWarningFormat("Unable to load ProjectConfig from {0}, error {1}", oculusProjectConfigAssetPath, e.Message);
  75. }
  76. if (projectConfig == null)
  77. {
  78. projectConfig = ScriptableObject.CreateInstance<OVRProjectConfig>();
  79. projectConfig.targetDeviceTypes = new List<DeviceType>();
  80. projectConfig.targetDeviceTypes.Add(DeviceType.Quest);
  81. projectConfig.handTrackingSupport = HandTrackingSupport.ControllersOnly;
  82. projectConfig.disableBackups = true;
  83. projectConfig.enableNSCConfig = true;
  84. projectConfig.focusAware = false;
  85. AssetDatabase.CreateAsset(projectConfig, oculusProjectConfigAssetPath);
  86. }
  87. return projectConfig;
  88. }
  89. public static void CommitProjectConfig(OVRProjectConfig projectConfig)
  90. {
  91. string oculusProjectConfigAssetPath = GetOculusProjectConfigAssetPath();
  92. if (AssetDatabase.GetAssetPath(projectConfig) != oculusProjectConfigAssetPath)
  93. {
  94. Debug.LogWarningFormat("The asset path of ProjectConfig is wrong. Expect {0}, get {1}", oculusProjectConfigAssetPath, AssetDatabase.GetAssetPath(projectConfig));
  95. }
  96. EditorUtility.SetDirty(projectConfig);
  97. }
  98. public static string ColorGamutToString(ColorGamut colorGamut)
  99. {
  100. switch(colorGamut)
  101. {
  102. case ColorGamut.Rec709: return "Rec. 709";
  103. case ColorGamut.DciP3: return "DCI-P3";
  104. case ColorGamut.Adobe: return "Adobe";
  105. case ColorGamut.Rec2020: return "Rec. 2020";
  106. default: return "<none>";
  107. }
  108. }
  109. }