1616using UnityEditor . Callbacks ;
1717using UnityEngine ;
1818using UnityEngine . Rendering ;
19+ using System . Collections . Generic ;
20+ using HTC . UnityPlugin . Utility ;
1921
2022namespace HTC . UnityPlugin . Vive
2123{
@@ -228,7 +230,7 @@ public override void OnPreferenceGUI()
228230
229231 if ( GUILayout . Button ( new GUIContent ( "Add Wave XR Plugin" , "Add " + WAVE_XR_PACKAGE_NAME + " to Package Manager" ) , GUILayout . ExpandWidth ( false ) ) )
230232 {
231- if ( ! ManifestUtils . CheckRegistryExists ( RegistryToolSettings . Instance ( ) . Registry ) )
233+ if ( ! CheckScopeExists ( RegistryToolSettings . Instance ( ) . Registry . Scopes ) )
232234 {
233235 ManifestUtils . AddRegistry ( RegistryToolSettings . Instance ( ) . Registry ) ;
234236 }
@@ -290,11 +292,11 @@ public override void OnPreferenceGUI()
290292 GUI . enabled = false ;
291293 EditorGUILayout . ToggleLeft ( new GUIContent ( enableWaveXRRenderModelTitle , VIUSettings . ENABLE_WAVE_XR_RENDER_MODEL_TOOLTIP + ". Required Wave XR Plugin Essence" ) , false , GUILayout . ExpandWidth ( true ) ) ;
292294 GUI . enabled = true ;
293-
295+
294296 s_guiChanged |= EditorGUI . EndChangeCheck ( ) ;
295297 if ( GUILayout . Button ( new GUIContent ( "Add Wave XR Plugin Essence" , "Add " + WAVE_XR_PACKAGE_ESSENCE_NAME + " to Package Manager" ) , GUILayout . ExpandWidth ( false ) ) )
296298 {
297- if ( ! ManifestUtils . CheckRegistryExists ( RegistryToolSettings . Instance ( ) . Registry ) )
299+ if ( ! CheckScopeExists ( RegistryToolSettings . Instance ( ) . Registry . Scopes ) )
298300 {
299301 ManifestUtils . AddRegistry ( RegistryToolSettings . Instance ( ) . Registry ) ;
300302 }
@@ -338,7 +340,7 @@ public override void OnPreferenceGUI()
338340 s_guiChanged |= EditorGUI . EndChangeCheck ( ) ;
339341 if ( GUILayout . Button ( new GUIContent ( "Update Wave XR Plugin Native" , "Update " + WAVE_XR_PACKAGE_NATIVE_NAME + " to latest version" ) , GUILayout . ExpandWidth ( false ) ) )
340342 {
341- if ( ! ManifestUtils . CheckRegistryExists ( RegistryToolSettings . Instance ( ) . Registry ) )
343+ if ( ! CheckScopeExists ( RegistryToolSettings . Instance ( ) . Registry . Scopes ) )
342344 {
343345 ManifestUtils . AddRegistry ( RegistryToolSettings . Instance ( ) . Registry ) ;
344346 }
@@ -382,7 +384,7 @@ public override void OnPreferenceGUI()
382384 s_guiChanged |= EditorGUI . EndChangeCheck ( ) ;
383385 if ( GUILayout . Button ( new GUIContent ( "Update Wave XR Plugin Native" , "Update " + WAVE_XR_PACKAGE_NATIVE_NAME + " to latest version" ) , GUILayout . ExpandWidth ( false ) ) )
384386 {
385- if ( ! ManifestUtils . CheckRegistryExists ( RegistryToolSettings . Instance ( ) . Registry ) )
387+ if ( ! CheckScopeExists ( RegistryToolSettings . Instance ( ) . Registry . Scopes ) )
386388 {
387389 ManifestUtils . AddRegistry ( RegistryToolSettings . Instance ( ) . Registry ) ;
388390 }
@@ -502,5 +504,60 @@ public void OnPreprocessBuild(BuildReport report)
502504 }
503505#endif
504506 }
507+
508+ [ Serializable ]
509+ private class UPMMenifestInfo
510+ {
511+ [ Serializable ]
512+ public struct ScopedRegistry
513+ {
514+ public string name ;
515+ public string url ;
516+ public List < string > scopes ;
517+ }
518+
519+ public List < ScopedRegistry > scopedRegistries ;
520+ }
521+
522+ private static UPMMenifestInfo menifestInfoTemp = new UPMMenifestInfo ( ) ;
523+ private static bool CheckScopeExists ( List < string > scopes )
524+ {
525+ if ( scopes == null || scopes . Count == 0 ) { return true ; }
526+
527+ var allScopes = ListPool < string > . Get ( ) ;
528+ try
529+ {
530+ var manifestString = File . ReadAllText ( RegistryToolSettings . Instance ( ) . ProjectManifestPath ) ;
531+ JsonUtility . FromJsonOverwrite ( manifestString , menifestInfoTemp ) ;
532+
533+ if ( menifestInfoTemp . scopedRegistries == null || menifestInfoTemp . scopedRegistries . Count == 0 ) { return false ; }
534+ foreach ( var reg in menifestInfoTemp . scopedRegistries )
535+ {
536+ var regScopes = reg . scopes ;
537+ if ( regScopes == null || regScopes . Count == 0 ) { continue ; }
538+ allScopes . AddRange ( regScopes ) ;
539+ }
540+
541+ if ( allScopes . Count > 0 )
542+ {
543+ foreach ( var scope in scopes )
544+ {
545+ if ( ! allScopes . Contains ( scope ) ) { return false ; }
546+ }
547+ return true ;
548+ }
549+ }
550+ catch ( Exception e )
551+ {
552+ Debug . LogException ( e ) ;
553+ }
554+ finally
555+ {
556+ ListPool < string > . Release ( allScopes ) ;
557+ allScopes = null ;
558+ }
559+
560+ return false ;
561+ }
505562 }
506563}
0 commit comments