@@ -44,20 +44,12 @@ public static void ShowWindow()
4444 [ EnumToggleButtons , HideLabel , PropertyOrder ( 0 ) ]
4545 [ SerializeField ]
4646 private SortMode _sortMode = SortMode . ByID ;
47-
48- [ HorizontalGroup ( "🔍 Search & Sort/SortRow" , width : 25 ) ]
49- [ Button ( "@_sortAscending ? \" ▲\" : \" ▼\" " , ButtonSizes . Medium ) ]
50- [ PropertyOrder ( 1 ) ]
51- private void ToggleSortDirection ( ) => _sortAscending = ! _sortAscending ;
52-
47+
48+ private BlockDataEditor _selectedBlock ;
49+ private BlockEditorDTO _blockDraft = new BlockEditorDTO ( ) ;
5350 private bool _sortAscending = true ;
5451 private Vector2 _scroll ;
5552
56- [ BoxGroup ( "🧾 Selected Block" , centerLabel : true ) ]
57- [ ShowInInspector , InlineEditor ( InlineEditorObjectFieldModes . Hidden ) ]
58- [ PropertyOrder ( 100 ) ]
59- private BlockDataEditor _selectedBlock ;
60-
6153 protected override void OnEnable ( )
6254 {
6355 base . OnEnable ( ) ;
@@ -80,17 +72,13 @@ protected override void DrawEditor(int index)
8072
8173 GUILayout . Space ( 10 ) ;
8274
83- SirenixEditorGUI . BeginBox ( ) ;
84- SirenixEditorGUI . BeginBoxHeader ( ) ;
85- SirenixEditorGUI . Title ( "📦 Existing Blocks" , null , TextAlignment . Center , true ) ;
86- SirenixEditorGUI . EndBoxHeader ( ) ;
87-
75+ DrawSelectedBlockSection ( ) ;
76+ GUILayout . Space ( 10 ) ;
77+
8878 _scroll = EditorGUILayout . BeginScrollView ( _scroll ) ;
8979 DrawExistingBlocks ( ) ;
9080 GUILayout . FlexibleSpace ( ) ;
9181 EditorGUILayout . EndScrollView ( ) ;
92-
93- SirenixEditorGUI . EndBox ( ) ;
9482 }
9583
9684 private void LoadOrCreateLibrary ( )
@@ -123,6 +111,48 @@ private void CreateLibrary()
123111 Debug . Log ( "✅ BlockLibrary created at " + path ) ;
124112 }
125113
114+ private void DrawSelectedBlockSection ( )
115+ {
116+ SirenixEditorGUI . BeginBox ( ) ;
117+ SirenixEditorGUI . BeginBoxHeader ( ) ;
118+ SirenixEditorGUI . Title ( "🎯 Selected Block" , null , TextAlignment . Center , true ) ;
119+ SirenixEditorGUI . EndBoxHeader ( ) ;
120+
121+ if ( _selectedBlock == null )
122+ {
123+ SirenixEditorGUI . InfoMessageBox ( "No block selected." ) ;
124+ }
125+ else
126+ {
127+ EditorGUILayout . BeginHorizontal ( ) ;
128+ GUILayout . Label ( _selectedBlock . Icon != null ? _selectedBlock . Icon . texture : Texture2D . grayTexture , GUILayout . Width ( 32 ) , GUILayout . Height ( 32 ) ) ;
129+ GUILayout . Label ( _selectedBlock . ID , SirenixGUIStyles . BoldLabel ) ;
130+ GUILayout . FlexibleSpace ( ) ;
131+ EditorGUILayout . EndHorizontal ( ) ;
132+
133+ GUILayout . Space ( 8 ) ;
134+
135+ // Поля редактирования DTO
136+ _blockDraft . Id = EditorGUILayout . TextField ( "ID" , _blockDraft . Id ) ;
137+ _blockDraft . Icon = ( Sprite ) EditorGUILayout . ObjectField ( "Icon" , _blockDraft . Icon , typeof ( Sprite ) , false ) ;
138+ _blockDraft . Prefab = ( GameObject ) EditorGUILayout . ObjectField ( "Prefab" , _blockDraft . Prefab , typeof ( GameObject ) , false ) ;
139+
140+ GUILayout . Space ( 4 ) ;
141+
142+ if ( GUILayout . Button ( "💾 Apply Changes" , GUILayout . Height ( 25 ) ) )
143+ {
144+ _blockDraft . ApplyTo ( _selectedBlock ) ;
145+ }
146+ }
147+
148+ SirenixEditorGUI . EndBox ( ) ;
149+ }
150+
151+ [ HorizontalGroup ( "🔍 Search & Sort/SortRow" , width : 25 ) ]
152+ [ Button ( "@_sortAscending ? \" ▲\" : \" ▼\" " , ButtonSizes . Medium ) ]
153+ [ PropertyOrder ( 1 ) ]
154+ private void ToggleSortDirection ( ) => _sortAscending = ! _sortAscending ;
155+
126156 private void DrawExistingBlocks ( )
127157 {
128158 if ( _blockLibrary . AllBlocks == null || _blockLibrary . AllBlocks . Count == 0 )
@@ -138,12 +168,15 @@ private void DrawExistingBlocks()
138168 blocks = blocks . FindAll ( b => b != null && b . ID . ToLower ( ) . Contains ( _searchFilter . ToLower ( ) ) ) ;
139169 }
140170
141- blocks . Sort ( ( a , b ) => _sortMode switch
171+ blocks . Sort ( ( a , b ) =>
142172 {
143- SortMode . ByID => string . Compare ( a . ID , b . ID , StringComparison . OrdinalIgnoreCase ) ,
144- SortMode . ByIconName => string . Compare ( a . Icon ? . name ?? "" , b . Icon ? . name ?? "" , StringComparison . OrdinalIgnoreCase ) ,
145- SortMode . ByPrefabName => SafeCompare ( a . Prefab , b . Prefab ) ,
146- _ => 0
173+ return _sortMode switch
174+ {
175+ SortMode . ByID => string . Compare ( a . ID , b . ID , StringComparison . OrdinalIgnoreCase ) ,
176+ SortMode . ByIconName => string . Compare ( a . Icon ? . name ?? "" , b . Icon ? . name ?? "" , StringComparison . OrdinalIgnoreCase ) ,
177+ SortMode . ByPrefabName => SafeCompare ( a . Prefab , b . Prefab ) ,
178+ _ => 0
179+ } ;
147180 } ) ;
148181
149182 if ( ! _sortAscending )
@@ -159,14 +192,12 @@ private void DrawExistingBlocks()
159192 SirenixEditorGUI . EndBoxHeader ( ) ;
160193
161194 GUILayout . BeginHorizontal ( ) ;
195+
162196 GUILayout . Label ( block . Icon != null ? block . Icon . texture : Texture2D . grayTexture , GUILayout . Width ( 32 ) , GUILayout . Height ( 32 ) ) ;
163197 GUILayout . FlexibleSpace ( ) ;
164198
165199 if ( GUILayout . Button ( "Select" , GUILayout . Width ( 60 ) ) )
166- {
167200 _selectedBlock = block ;
168- Selection . activeObject = block ;
169- }
170201
171202 if ( GUILayout . Button ( "X" , GUILayout . Width ( 20 ) ) )
172203 {
@@ -230,4 +261,28 @@ private int SafeCompare(UnityEngine.Object a, UnityEngine.Object b)
230261 }
231262 }
232263 }
233- }
264+
265+ [ Serializable ]
266+ public class BlockEditorDTO
267+ {
268+ public string Id ;
269+ public Sprite Icon ;
270+ public GameObject Prefab ;
271+
272+ public void LoadFrom ( BlockDataEditor block )
273+ {
274+ Id = block . ID ;
275+ Icon = block . Icon ;
276+ Prefab = block . Prefab ;
277+ }
278+
279+ public void ApplyTo ( BlockDataEditor block )
280+ {
281+ block . SetID ( Id ) ;
282+ block . SetIcon ( Icon ) ;
283+ block . SetPrefab ( Prefab ) ;
284+ EditorUtility . SetDirty ( block ) ;
285+ AssetDatabase . SaveAssets ( ) ;
286+ }
287+ }
288+ }
0 commit comments