Skip to content

Commit

Permalink
feat: Importer dependency section now additonally shows an icon for e…
Browse files Browse the repository at this point in the history
…ach depended asset
  • Loading branch information
Cammin committed Dec 8, 2024
1 parent 808db33 commit 9ddc70a
Showing 1 changed file with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Linq;
using System;
using System.Linq;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;

namespace LDtkUnity.Editor
{
Expand All @@ -9,6 +11,7 @@ internal sealed class LDtkSectionDependencies : LDtkSectionDrawer
private readonly SerializedObject _serializedObject;
private string[] _dependencies;
private Object[] _dependencyAssets;
private GUIContent[] _dependencyContent;

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

_dependencies = LDtkDependencyCache.Load(importerPath);
_dependencyAssets = new Object[_dependencies.Length];
_dependencyContent = new GUIContent[_dependencies.Length];

for (int i = 0; i < _dependencies.Length; i++)
{
_dependencyAssets[i] = AssetDatabase.LoadAssetAtPath<Object>(_dependencies[i]);
_dependencyContent[i] = new GUIContent
{
text = _dependencyAssets[i].name,
tooltip = _dependencies[i],
image = GetIconForDependency(_dependencyAssets[i].GetType(), _dependencies[i])
};
}

Texture2D GetIconForDependency(Type type, string assetPath)
{
AssetImporter importer = AssetImporter.GetAtPath(assetPath);

if (importer != null && importer is LDtkTilesetImporter)
{
return LDtkIconUtility.LoadTilesetFileIcon();
}

return AssetPreview.GetMiniTypeThumbnail(type);
}
}

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

protected override void DrawDropdownContent()
{
EditorGUIUtility.SetIconSize(Vector2.one * 16f);
for (int i = 0; i < _dependencies.Length; i++)
{
string dependency = _dependencies[i];
Object dependencyAsset = _dependencyAssets[i];

if (dependencyAsset == null)
{
continue;
}

GUIContent content = new GUIContent(dependencyAsset.name, dependency);

using (new LDtkGUIEnabledScope(false))
{
EditorGUILayout.ObjectField(content, dependencyAsset, typeof(Object), false);
EditorGUILayout.ObjectField(_dependencyContent[i], dependencyAsset, typeof(Object), false);
}
}
}
Expand Down

0 comments on commit 9ddc70a

Please sign in to comment.