Skip to content

Commit 82b5aa1

Browse files
committed
fix: Fixed the dependencies section from breaking if it fails to successfully load a dependency. Also will now draw dependencies even if they don't exist
1 parent 26fcf74 commit 82b5aa1

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

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

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Linq;
32
using UnityEditor;
43
using UnityEngine;
54
using Object = UnityEngine.Object;
@@ -47,7 +46,20 @@ public LDtkSectionDependencies(LDtkImporterEditor editor, SerializedObject seria
4746

4847
for (int i = 0; i < _dependencies.Length; i++)
4948
{
49+
//can be null!
5050
_dependencyAssets[i] = AssetDatabase.LoadAssetAtPath<Object>(_dependencies[i]);
51+
52+
if (_dependencyAssets[i] == null)
53+
{
54+
_dependencyContent[i] = new GUIContent
55+
{
56+
text = _dependencies[i] + " (missing)",
57+
tooltip = _dependencies[i],
58+
image = null
59+
};
60+
continue;
61+
}
62+
5163
_dependencyContent[i] = new GUIContent
5264
{
5365
text = _dependencyAssets[i].name,
@@ -71,31 +83,18 @@ Texture2D GetIconForDependency(Type type, string assetPath)
7183

7284
public override void Draw()
7385
{
74-
//don't draw this section at all if there are no dependencies
75-
if (_dependencyAssets.All(p => p == null))
76-
{
77-
return;
78-
}
79-
8086
LDtkEditorGUIUtility.DrawDivider();
8187
base.Draw();
8288
}
8389

8490
protected override void DrawDropdownContent()
8591
{
8692
EditorGUIUtility.SetIconSize(Vector2.one * 16f);
87-
for (int i = 0; i < _dependencies.Length; i++)
93+
using (new LDtkGUIEnabledScope(false))
8894
{
89-
Object dependencyAsset = _dependencyAssets[i];
90-
91-
if (dependencyAsset == null)
92-
{
93-
continue;
94-
}
95-
96-
using (new LDtkGUIEnabledScope(false))
95+
for (int i = 0; i < _dependencies.Length; i++)
9796
{
98-
EditorGUILayout.ObjectField(_dependencyContent[i], dependencyAsset, typeof(Object), false);
97+
EditorGUILayout.ObjectField(_dependencyContent[i], _dependencyAssets[i], typeof(Object), false);
9998
}
10099
}
101100
}

0 commit comments

Comments
 (0)