BlueGit

blue-star ggj-2020

Files

ggj-2020 / Assets / Oculus / VR / Editor / OVRManifestPreprocessor.cs

OVRManifestPreprocessor.cs

Project Import
timfa Tim Falken · pushed by timfa · 6 years ago
b77834a1 History
OVRManifestPreprocessor.cs 3.0 KiB Download Raw
1/************************************************************************************
2
3Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
4
5Licensed under the Oculus SDK License Version 3.4.1 (the "License");
6you may not use the Oculus SDK except in compliance with the License,
7which is provided at the time of installation or download, or which
8otherwise accompanies this software in either electronic or hard copy form.
9
10You may obtain a copy of the License at
11
12https://developer.oculus.com/licenses/sdk-3.4.1
13
14Unless required by applicable law or agreed to in writing, the Oculus SDK
15distributed under the License is distributed on an "AS IS" BASIS,
16WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17See the License for the specific language governing permissions and
18limitations under the License.
19
20************************************************************************************/
21
22using UnityEngine;
23using UnityEditor;
24using System.IO;
25
26public class OVRManifestPreprocessor
27{
28 [MenuItem("Oculus/Tools/Create store-compatible AndroidManifest.xml", false, 100000)]
29 public static void GenerateManifestForSubmission()
30 {
31 var so = ScriptableObject.CreateInstance(typeof(OVRPluginUpdaterStub));
32 var script = MonoScript.FromScriptableObject(so);
33 string assetPath = AssetDatabase.GetAssetPath(script);
34 string editorDir = Directory.GetParent(assetPath).FullName;
35 string srcFile = editorDir + "/AndroidManifest.OVRSubmission.xml";
36
37 if (!File.Exists(srcFile))
38 {
39 Debug.LogError("Cannot find Android manifest template for submission." +
40 " Please delete the OVR folder and reimport the Oculus Utilities.");
41 return;
42 }
43
44 string manifestFolder = Application.dataPath + "/Plugins/Android";
45
46 if (!Directory.Exists(manifestFolder))
47 Directory.CreateDirectory(manifestFolder);
48
49 string dstFile = manifestFolder + "/AndroidManifest.xml";
50
51 if (File.Exists(dstFile))
52 {
53 Debug.LogWarning("Cannot create Oculus store-compatible manifest due to conflicting file: \""
54 + dstFile + "\". Please remove it and try again.");
55 return;
56 }
57
58 string manifestText = File.ReadAllText(srcFile);
59 int dofTextIndex = manifestText.IndexOf("<!-- Request the headset DoF mode -->");
60 if (dofTextIndex != -1)
61 {
62 if (OVRDeviceSelector.isTargetDeviceQuest)
63 {
64 string headTrackingFeatureText = string.Format("<uses-feature android:name=\"android.hardware.vr.headtracking\" android:version=\"1\" android:required=\"{0}\" />",
65 OVRDeviceSelector.isTargetDeviceGearVrOrGo ? "false" : "true");
66 manifestText = manifestText.Insert(dofTextIndex, headTrackingFeatureText);
67 }
68 }
69 else
70 {
71 Debug.LogWarning("Manifest error: unable to locate headset DoF mode");
72 }
73
74 System.IO.File.WriteAllText(dstFile, manifestText);
75 AssetDatabase.Refresh();
76 }
77
78 [MenuItem("Oculus/Tools/Remove AndroidManifest.xml")]
79 public static void RemoveAndroidManifest()
80 {
81 AssetDatabase.DeleteAsset("Assets/Plugins/Android/AndroidManifest.xml");
82 AssetDatabase.Refresh();
83 }
84}