|
14 | 14 |
|
15 | 15 | // Only invoke custom build processor when building for Android. |
16 | 16 | #if UNITY_ANDROID |
17 | | -using System; |
18 | | -using UnityEditor; |
19 | | -using UnityEditor.Build; |
20 | | -using UnityEngine; |
21 | | -using UnityEditorInternal.VR; |
22 | | - |
23 | | -class PermissionsDemoBuildProcessor : IPreprocessBuild, IPostprocessBuild |
| 17 | +namespace GoogleVR.Demos |
24 | 18 | { |
25 | | - private const string SCENE_NAME_PERMISSIONS_DEMO = "PermissionsDemo"; |
26 | | - private const string VR_DEVICE_CARDBOARD = "cardboard"; |
27 | | - private const string VR_DEVICE_DAYDREAM = "daydream"; |
28 | | - |
29 | | - private bool m_cardboardAddedFromCode = false; |
30 | | - |
31 | | - public int callbackOrder |
32 | | - { |
33 | | - get { return 0; } |
34 | | - } |
| 19 | + using System; |
| 20 | + using UnityEditor; |
| 21 | + using UnityEditor.Build; |
| 22 | + using UnityEditorInternal.VR; |
35 | 23 |
|
36 | | - // OnPreprocessBuild() is called right before the build process begins. If it |
37 | | - // detects that the first enabled scene in the build arrays is the PermissionsDemo, |
38 | | - // and Daydream is in the VR SDKs, it will add Cardboard to the VR SDKs. Because |
39 | | - // the PermissionsDemo needs a perm statement in the Manifest while other demos don't. |
40 | | - // Adding Cardboard to VR SDKs will merge in the Manifest-Cardboard which has perm |
41 | | - // statement in it. |
42 | | - public void OnPreprocessBuild(BuildTarget target, string path) |
| 24 | + class PermissionsDemoBuildProcessor : IPreprocessBuild, IPostprocessBuild |
43 | 25 | { |
44 | | - m_cardboardAddedFromCode = false; |
| 26 | + private const string SCENE_NAME_PERMISSIONS_DEMO = "PermissionsDemo"; |
45 | 27 |
|
46 | | - string[] androidVrSDKs = VREditor.GetVREnabledDevicesOnTargetGroup(BuildTargetGroup.Android); |
| 28 | + private bool m_cardboardAddedFromCode = false; |
47 | 29 |
|
48 | | - EditorBuildSettingsScene[] scenes = EditorBuildSettings.scenes; |
| 30 | + public int callbackOrder |
| 31 | + { |
| 32 | + get { return 0; } |
| 33 | + } |
49 | 34 |
|
50 | | - // See if PermissionsDemo is the first enabled scene in the array of scenes to build. |
51 | | - for (int i = 0; i < scenes.Length; i++) |
| 35 | + // OnPreprocessBuild() is called right before the build process begins. If it |
| 36 | + // detects that the first enabled scene in the build arrays is the PermissionsDemo, |
| 37 | + // and Daydream is in the VR SDKs, it will add Cardboard to the VR SDKs. Because |
| 38 | + // the PermissionsDemo needs a perm statement in the Manifest while other demos don't. |
| 39 | + // Adding Cardboard to VR SDKs will merge in the Manifest-Cardboard which has perm |
| 40 | + // statement in it. |
| 41 | + public void OnPreprocessBuild(BuildTarget target, string path) |
52 | 42 | { |
53 | | - if (scenes[i].path.Contains(SCENE_NAME_PERMISSIONS_DEMO)) |
| 43 | + m_cardboardAddedFromCode = false; |
| 44 | + |
| 45 | + string[] androidVrSDKs = VREditor.GetVREnabledDevicesOnTargetGroup(BuildTargetGroup.Android); |
| 46 | + |
| 47 | + EditorBuildSettingsScene[] scenes = EditorBuildSettings.scenes; |
| 48 | + |
| 49 | + // See if PermissionsDemo is the first enabled scene in the array of scenes to build. |
| 50 | + for (int i = 0; i < scenes.Length; i++) |
54 | 51 | { |
55 | | - if (!scenes[i].enabled) |
| 52 | + if (scenes[i].path.Contains(SCENE_NAME_PERMISSIONS_DEMO)) |
56 | 53 | { |
57 | | - return; |
| 54 | + if (!scenes[i].enabled) |
| 55 | + { |
| 56 | + return; |
| 57 | + } |
| 58 | + else |
| 59 | + { |
| 60 | + break; |
| 61 | + } |
58 | 62 | } |
59 | 63 | else |
60 | 64 | { |
61 | | - break; |
| 65 | + if (scenes[i].enabled) |
| 66 | + { |
| 67 | + return; |
| 68 | + } |
62 | 69 | } |
63 | 70 | } |
64 | | - else |
| 71 | + |
| 72 | + bool hasCardboard = Array.Exists<string>(androidVrSDKs, |
| 73 | + element => element.Equals(GvrSettings.VR_SDK_CARDBOARD)); |
| 74 | + |
| 75 | + if (hasCardboard) |
65 | 76 | { |
66 | | - if (scenes[i].enabled) |
67 | | - { |
68 | | - return; |
69 | | - } |
| 77 | + return; |
70 | 78 | } |
71 | | - } |
72 | 79 |
|
73 | | - bool hasCardboard = Array.Exists<string>(androidVrSDKs, |
74 | | - element => element.Equals(VR_DEVICE_CARDBOARD)); |
| 80 | + bool hasDaydream = Array.Exists<string>(androidVrSDKs, |
| 81 | + element => element.Equals(GvrSettings.VR_SDK_DAYDREAM)); |
75 | 82 |
|
76 | | - if (hasCardboard) |
77 | | - { |
78 | | - return; |
79 | | - } |
| 83 | + if (!hasDaydream) |
| 84 | + { |
| 85 | + return; |
| 86 | + } |
80 | 87 |
|
81 | | - bool hasDaydream = Array.Exists<string>(androidVrSDKs, |
82 | | - element => element.Equals(VR_DEVICE_DAYDREAM)); |
| 88 | + string[] androidVrSDKsAppended = new string[androidVrSDKs.Length+1]; |
83 | 89 |
|
84 | | - if (!hasDaydream) |
85 | | - { |
86 | | - return; |
87 | | - } |
| 90 | + for (int i = 0; i < androidVrSDKs.Length; i++) |
| 91 | + { |
| 92 | + androidVrSDKsAppended[i] = androidVrSDKs[i]; |
| 93 | + } |
88 | 94 |
|
89 | | - string[] androidVrSDKsAppended = new string[androidVrSDKs.Length+1]; |
| 95 | + androidVrSDKsAppended[androidVrSDKsAppended.Length - 1] = GvrSettings.VR_SDK_CARDBOARD; |
90 | 96 |
|
91 | | - for (int i = 0; i < androidVrSDKs.Length; i++) |
92 | | - { |
93 | | - androidVrSDKsAppended[i] = androidVrSDKs[i]; |
| 97 | + VREditor.SetVREnabledOnTargetGroup( |
| 98 | + BuildTargetGroup.Android, true); |
| 99 | + VREditor.SetVREnabledDevicesOnTargetGroup( |
| 100 | + BuildTargetGroup.Android, |
| 101 | + androidVrSDKsAppended); |
| 102 | + |
| 103 | + m_cardboardAddedFromCode = true; |
94 | 104 | } |
95 | 105 |
|
96 | | - androidVrSDKsAppended[androidVrSDKsAppended.Length - 1] = VR_DEVICE_CARDBOARD; |
| 106 | + // OnPostprocessBuild() is called after the build process. It does appropriate cleanup |
| 107 | + // so that this script only affects build process for PermissionsDemo, not others. |
| 108 | + public void OnPostprocessBuild(BuildTarget target, string path) |
| 109 | + { |
| 110 | + if (!m_cardboardAddedFromCode) |
| 111 | + return; |
97 | 112 |
|
98 | | - VREditor.SetVREnabledOnTargetGroup( |
99 | | - BuildTargetGroup.Android, true); |
100 | | - VREditor.SetVREnabledDevicesOnTargetGroup( |
101 | | - BuildTargetGroup.Android, |
102 | | - androidVrSDKsAppended); |
| 113 | + string[] androidVrSDKs = VREditor.GetVREnabledDevicesOnTargetGroup(BuildTargetGroup.Android); |
103 | 114 |
|
104 | | - m_cardboardAddedFromCode = true; |
105 | | - } |
106 | | - |
107 | | - // OnPostprocessBuild() is called after the build process. It does appropriate cleanup |
108 | | - // so that this script only affects build process for PermissionsDemo, not others. |
109 | | - public void OnPostprocessBuild(BuildTarget target, string path) |
110 | | - { |
111 | | - if (!m_cardboardAddedFromCode) |
112 | | - return; |
| 115 | + // The enabled devices are modified somehow, which shouldn't happen. Abort the post build process. |
| 116 | + if (androidVrSDKs.Length == 0 || androidVrSDKs[androidVrSDKs.Length - 1] != GvrSettings.VR_SDK_CARDBOARD) |
| 117 | + { |
| 118 | + return; |
| 119 | + } |
113 | 120 |
|
114 | | - string[] androidVrSDKs = VREditor.GetVREnabledDevicesOnTargetGroup(BuildTargetGroup.Android); |
| 121 | + string[] androidVrSDKsShortened = new string[androidVrSDKs.Length - 1]; |
115 | 122 |
|
116 | | - // The enabled devices are modified somehow, which shouldn't happen. Abort the post build process. |
117 | | - if (androidVrSDKs.Length == 0 || androidVrSDKs[androidVrSDKs.Length - 1] != VR_DEVICE_CARDBOARD) |
118 | | - { |
119 | | - return; |
120 | | - } |
| 123 | + for (int i = 0; i < androidVrSDKsShortened.Length; i++) |
| 124 | + { |
| 125 | + androidVrSDKsShortened[i] = androidVrSDKs[i]; |
| 126 | + } |
121 | 127 |
|
122 | | - string[] androidVrSDKsShortened = new string[androidVrSDKs.Length - 1]; |
| 128 | + VREditor.SetVREnabledOnTargetGroup( |
| 129 | + BuildTargetGroup.Android, true); |
| 130 | + VREditor.SetVREnabledDevicesOnTargetGroup( |
| 131 | + BuildTargetGroup.Android, |
| 132 | + androidVrSDKsShortened); |
123 | 133 |
|
124 | | - for (int i = 0; i < androidVrSDKsShortened.Length; i++) |
125 | | - { |
126 | | - androidVrSDKsShortened[i] = androidVrSDKs[i]; |
| 134 | + m_cardboardAddedFromCode = false; |
127 | 135 | } |
128 | | - |
129 | | - VREditor.SetVREnabledOnTargetGroup( |
130 | | - BuildTargetGroup.Android, true); |
131 | | - VREditor.SetVREnabledDevicesOnTargetGroup( |
132 | | - BuildTargetGroup.Android, |
133 | | - androidVrSDKsShortened); |
134 | | - |
135 | | - m_cardboardAddedFromCode = false; |
136 | 136 | } |
137 | 137 | } |
138 | 138 | #endif // UNITY_ANDROID |
0 commit comments