@@ -57,6 +57,11 @@ internal sealed class LDtkSectionMain : LDtkSectionDrawer
5757 text = "Scale Entities" ,
5858 tooltip = "Apply a scale factor to entity prefab instances if they were resized in LDtk."
5959 } ;
60+ private static readonly GUIContent CustomSortingOrders = new GUIContent
61+ {
62+ text = "Custom Sorting Orders" ,
63+ tooltip = "Enable this to customize the sorting order for specific layers. If disabled, layers will automatically decrement starting from 0."
64+ } ;
6065
6166 protected override string GuiText => "Main" ;
6267 protected override string GuiTooltip => "This is the importer menu.\n " +
@@ -107,10 +112,56 @@ protected override void DrawDropdownContent()
107112 DrawField ( CreateLevelBoundsTrigger , LDtkProjectImporter . CREATE_LEVEL_BOUNDS_TRIGGER ) ;
108113 DrawField ( UseParallax , LDtkProjectImporter . USE_PARALLAX ) ;
109114 DrawField ( ScaleEntities , LDtkProjectImporter . SCALE_ENTITIES ) ;
115+
116+ DrawLayerSortingOrders ( ) ;
110117
111118 Editor . DrawDependenciesProperty ( ) ;
112119 }
113120
121+ private void DrawLayerSortingOrders ( )
122+ {
123+ SerializedProperty customProp = DrawField ( CustomSortingOrders , LDtkProjectImporter . CUSTOM_SORTING_ORDERS ) ;
124+
125+ if ( ! customProp . boolValue )
126+ {
127+ return ;
128+ }
129+
130+ SerializedProperty sortingOrderArray = SerializedObject . FindProperty ( LDtkProjectImporter . LAYER_SORTING_ORDERS ) ;
131+
132+ // Sync array with data
133+ LayerDefinition [ ] layers = _data . Defs . Layers ;
134+ if ( sortingOrderArray . arraySize != layers . Length )
135+ {
136+ sortingOrderArray . arraySize = layers . Length ;
137+ }
138+
139+ for ( int i = 0 ; i < layers . Length ; i ++ )
140+ {
141+ SerializedProperty element = sortingOrderArray . GetArrayElementAtIndex ( i ) ;
142+ SerializedProperty layerNameProp = element . FindPropertyRelative ( "Layer" ) ;
143+ SerializedProperty orderProp = element . FindPropertyRelative ( "Order" ) ;
144+
145+ string layerName = layers [ i ] . Identifier ;
146+
147+ // If name is different or empty (newly created), set it and default order
148+ if ( layerNameProp . stringValue != layerName )
149+ {
150+ layerNameProp . stringValue = layerName ;
151+ // Default auto generated value: -1, -2, etc. (starts at 0 and decrements)
152+ orderProp . intValue = - ( i + 1 ) ;
153+ }
154+
155+ EditorGUILayout . BeginHorizontal ( ) ;
156+ using ( new EditorGUI . DisabledScope ( true ) )
157+ {
158+ EditorGUILayout . TextField ( layerNameProp . stringValue ) ;
159+ }
160+ EditorGUILayout . PropertyField ( orderProp , GUIContent . none ) ;
161+ EditorGUILayout . EndHorizontal ( ) ;
162+ }
163+ }
164+
114165 private void PixelsPerUnitField ( )
115166 {
116167 GUIContent content = new GUIContent ( PixelsPerUnit )
0 commit comments