1- using System . Linq ;
1+ using System ;
2+ using System . Linq ;
23using UnityEditor ;
34using UnityEngine ;
5+ using Object = UnityEngine . Object ;
46
57namespace 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