Skip to content

Commit e062fca

Browse files
committed
feat: added display prefab in DrawExistingBlocks
1 parent 92cc093 commit e062fca

File tree

4 files changed

+55
-32
lines changed

4 files changed

+55
-32
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using UnityEditor;
3+
using UnityEngine;
4+
5+
namespace Code.LevelEditor
6+
{
7+
[Serializable]
8+
public class BlockEditorDto
9+
{
10+
public string Id;
11+
public Sprite Icon;
12+
public GameObject Prefab;
13+
14+
public void LoadFrom(BlockDataEditor block)
15+
{
16+
Id = block.ID;
17+
Icon = block.Icon;
18+
Prefab = block.Prefab;
19+
}
20+
21+
public void ApplyTo(BlockDataEditor block)
22+
{
23+
block.SetID(Id);
24+
block.SetIcon(Icon);
25+
block.SetPrefab(Prefab);
26+
EditorUtility.SetDirty(block);
27+
AssetDatabase.SaveAssets();
28+
}
29+
}
30+
}

Assets/Code/LevelEditor/BlockEditorDto.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Code/LevelEditor/BlockLibraryWindow.cs

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static void ShowWindow()
4343
private SortMode _sortMode = SortMode.ByID;
4444

4545
private BlockDataEditor _selectedBlock;
46-
private BlockEditorDTO _blockDraft = new BlockEditorDTO();
46+
private BlockEditorDto _blockDraft = new BlockEditorDto();
4747
private bool _sortAscending = true;
4848
private Vector2 _scroll;
4949

@@ -162,7 +162,7 @@ private void DrawExistingBlocks()
162162
if (_blockLibrary.AllBlocks == null || _blockLibrary.AllBlocks.Count == 0)
163163
{
164164
SirenixEditorGUI.InfoMessageBox("No blocks found.");
165-
SirenixEditorGUI.EndBox(); // не забываем закрыть
165+
SirenixEditorGUI.EndBox();
166166
return;
167167
}
168168

@@ -198,11 +198,26 @@ private void DrawExistingBlocks()
198198
SirenixEditorGUI.EndBoxHeader();
199199

200200
GUILayout.BeginHorizontal();
201+
202+
GUILayout.Label(block.Icon != null ? block.Icon.texture : Texture2D.grayTexture,
203+
GUILayout.Width(32), GUILayout.Height(32));
201204

202-
GUILayout.Label(block.Icon != null ? block.Icon.texture : Texture2D.grayTexture, GUILayout.Width(32),
203-
GUILayout.Height(32));
204-
GUILayout.FlexibleSpace();
205+
GUILayout.Space(10);
206+
207+
if (block.Prefab != null)
208+
{
209+
GUILayout.Label(AssetPreview.GetAssetPreview(block.Prefab) ?? Texture2D.grayTexture,
210+
GUILayout.Width(32), GUILayout.Height(32));
211+
GUILayout.Label(block.Prefab.name, GUILayout.Width(100));
212+
}
213+
else
214+
{
215+
GUILayout.Label(Texture2D.grayTexture, GUILayout.Width(32), GUILayout.Height(32));
216+
GUILayout.Label("None", GUILayout.Width(100));
217+
}
205218

219+
GUILayout.FlexibleSpace();
220+
206221
if (GUILayout.Button("Select", GUILayout.Width(60)))
207222
{
208223
_selectedBlock = block;
@@ -211,8 +226,7 @@ private void DrawExistingBlocks()
211226

212227
if (GUILayout.Button("X", GUILayout.Width(20)))
213228
{
214-
if (EditorUtility.DisplayDialog("Delete Block", $"Are you sure you want to delete '{block.ID}'?",
215-
"Yes", "No"))
229+
if (EditorUtility.DisplayDialog("Delete Block", $"Are you sure you want to delete '{block.ID}'?", "Yes", "No"))
216230
{
217231
var path = AssetDatabase.GetAssetPath(block);
218232
_blockLibrary.AllBlocks.Remove(block);
@@ -272,28 +286,4 @@ private int SafeCompare(UnityEngine.Object a, UnityEngine.Object b)
272286
}
273287
}
274288
}
275-
276-
[Serializable]
277-
public class BlockEditorDTO
278-
{
279-
public string Id;
280-
public Sprite Icon;
281-
public GameObject Prefab;
282-
283-
public void LoadFrom(BlockDataEditor block)
284-
{
285-
Id = block.ID;
286-
Icon = block.Icon;
287-
Prefab = block.Prefab;
288-
}
289-
290-
public void ApplyTo(BlockDataEditor block)
291-
{
292-
block.SetID(Id);
293-
block.SetIcon(Icon);
294-
block.SetPrefab(Prefab);
295-
EditorUtility.SetDirty(block);
296-
AssetDatabase.SaveAssets();
297-
}
298-
}
299289
}

Assets/Resources/StaticData/BlocksData/Test_Boss.asset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ MonoBehaviour:
1414
m_EditorClassIdentifier:
1515
id: Test_Boss
1616
icon: {fileID: 21300000, guid: 8f2913d99ed313748b01466c10eb10f1, type: 3}
17-
prefab: {fileID: 0}
17+
prefab: {fileID: 100002, guid: 6b08ca44c9b2a1a4c99dff3ef0acc5c3, type: 3}

0 commit comments

Comments
 (0)