66using UnityEditor . AddressableAssets . Settings ;
77using UnityEditorInternal ;
88using UnityEngine ;
9+ using UnityEngine . UIElements ;
910
1011// ReSharper disable once CheckNamespace
1112
@@ -59,7 +60,7 @@ public abstract class UiConfigsEditor<TSet> : Editor
5960 "All the Addressable addresses for every UiPresenter in the game.\n " +
6061 "The second field is the layer where the UiPresenter should be shown. " +
6162 "The higher the value, the closer is the UiPresenter to the camera.\n " +
62- "If the UiPresenter contains a Canvas in the root, the layer value is the same of the Canvas sorting order" ) ;
63+ "If the UiPresenter contains a Canvas/UIDocument in the root, the layer value is the same of the UI sorting order" ) ;
6364 private readonly GUIContent _uiSetConfigGuiContent = new GUIContent ( "Ui Set" ,
6465 "All the Ui Sets in the game.\n " +
6566 "A UiSet groups a list of UiConfigs and shows them all at the same time via the UiService.\n " +
@@ -171,13 +172,22 @@ private void InitConfigValues()
171172
172173 _assetsPath . Add ( assetList [ i ] . AssetPath ) ;
173174
174- var canvas = uiPresenter . GetComponent < Canvas > ( ) ;
175+ var sortingOrder = - 1 ;
176+ if ( uiPresenter . TryGetComponent < Canvas > ( out var canvas ) )
177+ {
178+ sortingOrder = canvas . sortingOrder ;
179+ }
180+ else if ( uiPresenter . TryGetComponent < UIDocument > ( out var document ) )
181+ {
182+ sortingOrder = ( int ) document . sortingOrder ;
183+ }
184+
175185 var indexMatch = configsCache . FindIndex ( configCheck => configCheck . AddressableAddress == assetAddress ) ;
176186 var type = uiPresenter . GetType ( ) ;
177187 var config = new UiConfig
178188 {
179189 AddressableAddress = assetList [ i ] . address ,
180- Layer = canvas == null ? 0 : canvas . sortingOrder ,
190+ Layer = sortingOrder < 0 ? 0 : sortingOrder ,
181191 UiType = type ,
182192 LoadSynchronously = Attribute . IsDefined ( type , typeof ( LoadSynchronouslyAttribute ) )
183193
@@ -188,7 +198,7 @@ private void InitConfigValues()
188198 uiConfigsAddress . Add ( config . AddressableAddress ) ;
189199 _uiConfigsType . Add ( config . UiType . AssemblyQualifiedName ) ;
190200
191- config . Layer = canvas == null ? configsCache [ indexMatch ] . Layer : config . Layer ;
201+ config . Layer = sortingOrder < 0 ? configsCache [ indexMatch ] . Layer : config . Layer ;
192202 }
193203
194204 configs . Add ( config ) ;
@@ -267,14 +277,21 @@ private void DrawUiConfigElement(Rect rect, int index, bool isActive, bool isFoc
267277
268278 layer . intValue = newLayer ;
269279
270- var canvas = AssetDatabase . LoadAssetAtPath < GameObject > ( _assetsPath [ index ] ) . GetComponent < Canvas > ( ) ;
271- if ( canvas != null )
280+ var ui = AssetDatabase . LoadAssetAtPath < GameObject > ( _assetsPath [ index ] ) ;
281+ if ( ui . TryGetComponent < Canvas > ( out var canvas ) )
272282 {
273283 canvas . sortingOrder = newLayer ;
274284
275285 EditorUtility . SetDirty ( canvas ) ;
276286 AssetDatabase . SaveAssets ( ) ;
277287 }
288+ else if ( ui . TryGetComponent < UIDocument > ( out var document ) )
289+ {
290+ document . sortingOrder = newLayer ;
291+
292+ EditorUtility . SetDirty ( document ) ;
293+ AssetDatabase . SaveAssets ( ) ;
294+ }
278295
279296 Resources . UnloadUnusedAssets ( ) ;
280297 }
0 commit comments