OVRManifestPreprocessor.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 UnityEngine;
  16. using UnityEditor;
  17. using System.IO;
  18. public class OVRManifestPreprocessor
  19. {
  20. [MenuItem("Oculus/Tools/Create store-compatible AndroidManifest.xml", false, 100000)]
  21. public static void GenerateManifestForSubmission()
  22. {
  23. var so = ScriptableObject.CreateInstance(typeof(OVRPluginUpdaterStub));
  24. var script = MonoScript.FromScriptableObject(so);
  25. string assetPath = AssetDatabase.GetAssetPath(script);
  26. string editorDir = Directory.GetParent(assetPath).FullName;
  27. string srcFile = editorDir + "/AndroidManifest.OVRSubmission.xml";
  28. if (!File.Exists(srcFile))
  29. {
  30. Debug.LogError("Cannot find Android manifest template for submission." +
  31. " Please delete the OVR folder and reimport the Oculus Utilities.");
  32. return;
  33. }
  34. string manifestFolder = Application.dataPath + "/Plugins/Android";
  35. if (!Directory.Exists(manifestFolder))
  36. Directory.CreateDirectory(manifestFolder);
  37. string dstFile = manifestFolder + "/AndroidManifest.xml";
  38. if (File.Exists(dstFile))
  39. {
  40. Debug.LogWarning("Cannot create Oculus store-compatible manifest due to conflicting file: \""
  41. + dstFile + "\". Please remove it and try again.");
  42. return;
  43. }
  44. string manifestText = File.ReadAllText(srcFile);
  45. int dofTextIndex = manifestText.IndexOf("<!-- Request the headset DoF mode -->");
  46. if (dofTextIndex != -1)
  47. {
  48. if (OVRDeviceSelector.isTargetDeviceQuest)
  49. {
  50. string headTrackingFeatureText = string.Format("<uses-feature android:name=\"android.hardware.vr.headtracking\" android:version=\"1\" android:required=\"{0}\" />",
  51. OVRDeviceSelector.isTargetDeviceGearVrOrGo ? "false" : "true");
  52. manifestText = manifestText.Insert(dofTextIndex, headTrackingFeatureText);
  53. }
  54. }
  55. else
  56. {
  57. Debug.LogWarning("Manifest error: unable to locate headset DoF mode");
  58. }
  59. int handTrackingTextIndex = manifestText.IndexOf("<!-- Request the headset handtracking mode -->");
  60. if (handTrackingTextIndex != -1)
  61. {
  62. if (OVRDeviceSelector.isTargetDeviceQuest)
  63. {
  64. OVRProjectConfig.HandTrackingSupport targetHandTrackingSupport = OVRProjectConfig.GetProjectConfig().handTrackingSupport;
  65. bool handTrackingEntryNeeded = (targetHandTrackingSupport != OVRProjectConfig.HandTrackingSupport.ControllersOnly);
  66. bool handTrackingRequired = (targetHandTrackingSupport == OVRProjectConfig.HandTrackingSupport.HandsOnly);
  67. if (handTrackingEntryNeeded)
  68. {
  69. string handTrackingFeatureText = string.Format("<uses-feature android:name=\"oculus.software.handtracking\" android:required=\"{0}\" />",
  70. handTrackingRequired ? "true" : "false");
  71. string handTrackingPermissionText = string.Format("<uses-permission android:name=\"oculus.permission.handtracking\" />");
  72. manifestText = manifestText.Insert(handTrackingTextIndex, handTrackingPermissionText);
  73. manifestText = manifestText.Insert(handTrackingTextIndex, handTrackingFeatureText);
  74. }
  75. }
  76. }
  77. else
  78. {
  79. Debug.LogWarning("Manifest error: unable to locate headset handtracking mode");
  80. }
  81. #if !UNITY_2018_2_OR_NEWER
  82. int iconLabelText = manifestText.IndexOf("android:icon=\"@mipmap/app_icon\"");
  83. if(iconLabelText != -1)
  84. {
  85. manifestText = manifestText.Replace("android:icon=\"@mipmap/app_icon\"", "android:icon=\"@drawable/app_icon\"");
  86. }
  87. else
  88. {
  89. Debug.LogWarning("Manifest error: failed to update icon label for older version of Unity");
  90. }
  91. #endif
  92. System.IO.File.WriteAllText(dstFile, manifestText);
  93. AssetDatabase.Refresh();
  94. }
  95. [MenuItem("Oculus/Tools/Remove AndroidManifest.xml")]
  96. public static void RemoveAndroidManifest()
  97. {
  98. AssetDatabase.DeleteAsset("Assets/Plugins/Android/AndroidManifest.xml");
  99. AssetDatabase.Refresh();
  100. }
  101. }