1+ using System . Collections ;
2+ using System . Collections . Generic ;
3+ using UnityEditor ;
4+ using UnityEngine ;
5+
6+ #if UNITY_2018_1_OR_NEWER
7+ using HTC . UnityPlugin . UPMRegistryTool . Editor . Utils ;
8+ using HTC . UnityPlugin . UPMRegistryTool . Editor . Configs ;
9+ #endif
10+
11+ #if VIU_XR_GENERAL_SETTINGS
12+ using UnityEditor . XR . Management ;
13+ using UnityEngine . XR . Management ;
14+ #endif
15+
16+ #if VIU_OPENXR
17+ using UnityEngine . XR . OpenXR ;
18+ using UnityEngine . XR . OpenXR . Features . Interactions ;
19+ #endif
20+
21+ namespace HTC . UnityPlugin . Vive
22+ {
23+ #if VIU_OPENXR
24+ public class OpenXRAndroidOculusRecommendedSettings : VIUVersionCheck . RecommendedSettingCollection
25+ {
26+ public OpenXRAndroidOculusRecommendedSettings ( )
27+ {
28+ Add ( new VIUVersionCheck . RecommendedSetting < bool > ( )
29+ {
30+ settingTitle = "Add Oculus Touch Controller Profile" ,
31+ skipCheckFunc = ( ) => ! VIUSettingsEditor . supportOpenXRAndroidOculus ,
32+ currentValueFunc = ( ) =>
33+ {
34+ var feature = OpenXRSettings . ActiveBuildTargetInstance . GetFeature < OculusTouchControllerProfile > ( ) ;
35+ return feature != null && feature . enabled ;
36+ } ,
37+ setValueFunc = v =>
38+ {
39+ var feature = OpenXRSettings . ActiveBuildTargetInstance . GetFeature < OculusTouchControllerProfile > ( ) ;
40+ if ( feature != null ) { feature . enabled = true ; }
41+ } ,
42+ recommendedValue = true ,
43+ } ) ;
44+ }
45+ }
46+ #endif
47+
48+ public static partial class VIUSettingsEditor
49+ {
50+ public const string OCULUS_QUEST_OPENXR_FEATURE_ID = "com.unity.openxr.feature.oculusquest" ;
51+
52+ public static bool canSupportOpenXRAndroidOculus
53+ {
54+ get { return OpenXRAndroidOculusSettings . instance . canSupport ; }
55+ }
56+
57+ public static bool supportOpenXRAndroidOculus
58+ {
59+ get { return OpenXRAndroidOculusSettings . instance . support ; }
60+ set { OpenXRAndroidOculusSettings . instance . support = value ; }
61+ }
62+
63+ private class OpenXRAndroidOculusSettings : VRPlatformSetting
64+ {
65+ public static OpenXRAndroidOculusSettings instance { get ; private set ; }
66+
67+ public OpenXRAndroidOculusSettings ( ) { instance = this ; }
68+
69+ public override int order { get { return 105 ; } }
70+
71+ protected override BuildTargetGroup requirdPlatform { get { return BuildTargetGroup . Android ; } }
72+
73+ public override bool canSupport
74+ {
75+ get
76+ {
77+ if ( activeBuildTargetGroup != requirdPlatform ) { return false ; }
78+ if ( PackageManagerHelper . IsPackageInList ( WAVE_XR_PACKAGE_NAME ) ) { return false ; }
79+ if ( PackageManagerHelper . IsPackageInList ( WAVE_XR_OPENXR_PACKAGE ) ) { return false ; }
80+ if ( PackageManagerHelper . IsPackageInList ( OCULUS_XR_PACKAGE_NAME ) ) { return false ; }
81+ if ( ! PackageManagerHelper . IsPackageInList ( OPENXR_PLUGIN_PACKAGE_NAME ) ) { return false ; }
82+ return true ;
83+ }
84+ }
85+
86+ public override bool support
87+ {
88+ get
89+ {
90+ if ( ! canSupport ) { return false ; }
91+ if ( ! VIUSettings . activateUnityXRModule ) { return false ; }
92+ if ( ! XRPluginManagementUtils . IsXRLoaderEnabled ( OPENXR_PLUGIN_LOADER_NAME , requirdPlatform ) ) { return false ; }
93+ if ( IsOpenXRFeatureGroupEnabled ( requirdPlatform , WAVE_XR_OPENXR_FEATURE_ID ) ) { return false ; }
94+ if ( ! IsOpenXRFeatureGroupEnabled ( requirdPlatform , OCULUS_QUEST_OPENXR_FEATURE_ID ) ) { return false ; }
95+ return true ;
96+ }
97+ set
98+ {
99+ if ( value ) { VIUSettings . activateUnityXRModule = true ; }
100+ if ( value ) { XRPluginManagementUtils . SetXRLoaderEnabled ( OPENXR_PLUGIN_LOADER_TYPE , requirdPlatform , true ) ; }
101+ if ( value ) { SetOpenXRFeatureGroupEnable ( requirdPlatform , WAVE_XR_OPENXR_FEATURE_ID , false ) ; }
102+ SetOpenXRFeatureGroupEnable ( requirdPlatform , OCULUS_QUEST_OPENXR_FEATURE_ID , value ) ;
103+ }
104+ }
105+
106+ private static GUIContent s_title = new GUIContent ( "OpenXR Android for Oculus (Experimental)" , "Oculus Quest" ) ;
107+ public override void OnPreferenceGUI ( )
108+ {
109+ const float toggleWidth = 263f ;
110+ if ( canSupport )
111+ {
112+ var wasSupported = support ;
113+ var shouldSupport = Foldouter . ShowFoldoutBlankWithEnabledToggle ( s_title , wasSupported ) ;
114+ if ( wasSupported != shouldSupport )
115+ {
116+ support = shouldSupport ;
117+ }
118+ }
119+ else
120+ {
121+ GUILayout . BeginHorizontal ( ) ;
122+ Foldouter . ShowFoldoutBlank ( ) ;
123+
124+ #if ! UNITY_2020_2_OR_NEWER
125+ GUI . enabled = false ;
126+ ShowToggle ( new GUIContent ( s_title . text , s_title . tooltip + ". Unity 2020.2 or later version required." ) , false , GUILayout . Width ( toggleWidth ) ) ;
127+ GUI . enabled = true ;
128+ #else
129+ if ( activeBuildTargetGroup != requirdPlatform )
130+ {
131+ GUI . enabled = false ;
132+ ShowToggle ( s_title , false , GUILayout . Width ( toggleWidth ) ) ;
133+ GUI . enabled = true ;
134+ GUILayout . FlexibleSpace ( ) ;
135+ ShowSwitchPlatformButton ( requirdPlatform , BuildTarget . Android ) ;
136+ }
137+ else if ( PackageManagerHelper . IsPackageInList ( WAVE_XR_PACKAGE_NAME ) )
138+ {
139+ GUI . enabled = false ;
140+ ShowToggle ( s_title , false , GUILayout . Width ( toggleWidth ) ) ;
141+ GUI . enabled = true ;
142+ GUILayout . FlexibleSpace ( ) ;
143+
144+ var btnLabel = new GUIContent ( ) ;
145+ string tmPkgName ;
146+ if ( PackageManagerHelper . IsPackageInList ( WAVE_XR_PACKAGE_ESSENCE_NAME ) )
147+ {
148+ btnLabel . text = "Remove Wave XR Plugin - Essence" ;
149+ btnLabel . tooltip = "Conflict package found. Remove " + WAVE_XR_PACKAGE_ESSENCE_NAME + " from Package Manager" ;
150+ tmPkgName = WAVE_XR_PACKAGE_ESSENCE_NAME ;
151+ }
152+ else if ( PackageManagerHelper . IsPackageInList ( WAVE_XR_PACKAGE_NATIVE_NAME ) )
153+ {
154+ btnLabel . text = "Remove Wave XR Plugin - Native" ;
155+ btnLabel . tooltip = "Conflict package found. Remove " + WAVE_XR_PACKAGE_NATIVE_NAME + " from Package Manager" ;
156+ tmPkgName = WAVE_XR_PACKAGE_NATIVE_NAME ;
157+ }
158+ else
159+ {
160+ btnLabel . text = "Remove Wave XR Plugin" ;
161+ btnLabel . tooltip = "Conflict package found. Remove " + WAVE_XR_PACKAGE_NAME + " from Package Manager" ;
162+ tmPkgName = WAVE_XR_PACKAGE_NAME ;
163+ }
164+
165+ if ( GUILayout . Button ( btnLabel , GUILayout . ExpandWidth ( false ) ) )
166+ {
167+ PackageManagerHelper . RemovePackage ( tmPkgName ) ;
168+ }
169+ }
170+ else if ( PackageManagerHelper . IsPackageInList ( WAVE_XR_OPENXR_PACKAGE ) )
171+ {
172+ GUI . enabled = false ;
173+ ShowToggle ( s_title , false , GUILayout . Width ( toggleWidth ) ) ;
174+ GUI . enabled = true ;
175+ GUILayout . FlexibleSpace ( ) ;
176+
177+ if ( GUILayout . Button ( new GUIContent ( "Remove Wave XR Plugin - OpenXR" , "Conflict package found. Remove " + WAVE_XR_OPENXR_PACKAGE + " from Package Manager" ) , GUILayout . ExpandWidth ( false ) ) )
178+ {
179+ PackageManagerHelper . RemovePackage ( WAVE_XR_OPENXR_PACKAGE ) ;
180+ }
181+ }
182+ else if ( PackageManagerHelper . IsPackageInList ( OCULUS_XR_PACKAGE_NAME ) )
183+ {
184+ GUI . enabled = false ;
185+ ShowToggle ( s_title , false , GUILayout . Width ( toggleWidth ) ) ;
186+ GUI . enabled = true ;
187+ GUILayout . FlexibleSpace ( ) ;
188+
189+ if ( GUILayout . Button ( new GUIContent ( "Remove Oculus XR Plugin" , "Conflict package found. Remove " + OCULUS_XR_PACKAGE_NAME + " from Package Manager" ) , GUILayout . ExpandWidth ( false ) ) )
190+ {
191+ PackageManagerHelper . RemovePackage ( OCULUS_XR_PACKAGE_NAME ) ;
192+ }
193+ }
194+ else if ( ! PackageManagerHelper . IsPackageInList ( OPENXR_PLUGIN_PACKAGE_NAME ) )
195+ {
196+ GUI . enabled = false ;
197+ ShowToggle ( new GUIContent ( s_title ) , false , GUILayout . Width ( toggleWidth ) ) ;
198+ GUI . enabled = true ;
199+ GUILayout . FlexibleSpace ( ) ;
200+
201+ if ( GUILayout . Button ( new GUIContent ( "Add OpenXR Plugin" , "Add " + OPENXR_PLUGIN_PACKAGE_NAME + " to Package Manager" ) , GUILayout . ExpandWidth ( false ) ) )
202+ {
203+ PackageManagerHelper . AddToPackageList ( OPENXR_PLUGIN_PACKAGE_NAME ) ;
204+ }
205+ }
206+ else if ( ! XRPluginManagementUtils . IsXRLoaderEnabled ( OPENXR_PLUGIN_LOADER_NAME , requirdPlatform ) )
207+ {
208+ GUI . enabled = false ;
209+ ShowToggle ( new GUIContent ( s_title ) , false , GUILayout . Width ( toggleWidth ) ) ;
210+ GUI . enabled = true ;
211+ GUILayout . FlexibleSpace ( ) ;
212+
213+ if ( GUILayout . Button ( new GUIContent ( "Enable OpenXR Loader" , "Enable OpenXR Loader in XR Plug-in Management" ) , GUILayout . ExpandWidth ( false ) ) )
214+ {
215+ if ( ! ShowXRPluginManagementSection ( ) )
216+ {
217+ Debug . LogError ( "Fail opening XR Plug-in Management page, please enable OpenXR Loader manually." ) ;
218+ }
219+ }
220+ }
221+ #endif
222+ GUILayout . EndHorizontal ( ) ;
223+ }
224+ }
225+ }
226+ }
227+ }
0 commit comments