Skip to content

Commit 9ddc70a

Browse files
committed
feat: Importer dependency section now additonally shows an icon for each depended asset
1 parent 808db33 commit 9ddc70a

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

Assets/LDtkUnity/Editor/CustomEditor/SectionDrawers/LDtkSectionDependencies.cs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
using System.Linq;
1+
using System;
2+
using System.Linq;
23
using UnityEditor;
34
using UnityEngine;
5+
using Object = UnityEngine.Object;
46

57
namespace LDtkUnity.Editor
68
{
@@ -9,6 +11,7 @@ internal sealed class LDtkSectionDependencies : LDtkSectionDrawer
911
private readonly SerializedObject _serializedObject;
1012
private string[] _dependencies;
1113
private Object[] _dependencyAssets;
14+
private GUIContent[] _dependencyContent;
1215

1316
protected override string GuiText => "Dependencies";
1417
protected override string GuiTooltip => "Dependencies that were defined since the last import.\n" +
@@ -40,15 +43,35 @@ public LDtkSectionDependencies(LDtkImporterEditor editor, SerializedObject seria
4043

4144
_dependencies = LDtkDependencyCache.Load(importerPath);
4245
_dependencyAssets = new Object[_dependencies.Length];
46+
_dependencyContent = new GUIContent[_dependencies.Length];
4347

4448
for (int i = 0; i < _dependencies.Length; i++)
4549
{
4650
_dependencyAssets[i] = AssetDatabase.LoadAssetAtPath<Object>(_dependencies[i]);
51+
_dependencyContent[i] = new GUIContent
52+
{
53+
text = _dependencyAssets[i].name,
54+
tooltip = _dependencies[i],
55+
image = GetIconForDependency(_dependencyAssets[i].GetType(), _dependencies[i])
56+
};
57+
}
58+
59+
Texture2D GetIconForDependency(Type type, string assetPath)
60+
{
61+
AssetImporter importer = AssetImporter.GetAtPath(assetPath);
62+
63+
if (importer != null && importer is LDtkTilesetImporter)
64+
{
65+
return LDtkIconUtility.LoadTilesetFileIcon();
66+
}
67+
68+
return AssetPreview.GetMiniTypeThumbnail(type);
4769
}
4870
}
4971

5072
public override void Draw()
5173
{
74+
//don't draw this section at all if there are no dependencies
5275
if (_dependencyAssets.All(p => p == null))
5376
{
5477
return;
@@ -60,21 +83,19 @@ public override void Draw()
6083

6184
protected override void DrawDropdownContent()
6285
{
86+
EditorGUIUtility.SetIconSize(Vector2.one * 16f);
6387
for (int i = 0; i < _dependencies.Length; i++)
6488
{
65-
string dependency = _dependencies[i];
6689
Object dependencyAsset = _dependencyAssets[i];
6790

6891
if (dependencyAsset == null)
6992
{
7093
continue;
7194
}
7295

73-
GUIContent content = new GUIContent(dependencyAsset.name, dependency);
74-
7596
using (new LDtkGUIEnabledScope(false))
7697
{
77-
EditorGUILayout.ObjectField(content, dependencyAsset, typeof(Object), false);
98+
EditorGUILayout.ObjectField(_dependencyContent[i], dependencyAsset, typeof(Object), false);
7899
}
79100
}
80101
}

0 commit comments

Comments
 (0)