Skip to content

Commit

Permalink
fix: Fixed the dependencies section from breaking if it fails to succ…
Browse files Browse the repository at this point in the history
…essfully load a dependency. Also will now draw dependencies even if they don't exist
  • Loading branch information
Cammin committed Dec 15, 2024
1 parent 26fcf74 commit 82b5aa1
Showing 1 changed file with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Linq;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
Expand Down Expand Up @@ -47,7 +46,20 @@ public LDtkSectionDependencies(LDtkImporterEditor editor, SerializedObject seria

for (int i = 0; i < _dependencies.Length; i++)
{
//can be null!
_dependencyAssets[i] = AssetDatabase.LoadAssetAtPath<Object>(_dependencies[i]);

if (_dependencyAssets[i] == null)
{
_dependencyContent[i] = new GUIContent
{
text = _dependencies[i] + " (missing)",
tooltip = _dependencies[i],
image = null
};
continue;
}

_dependencyContent[i] = new GUIContent
{
text = _dependencyAssets[i].name,
Expand All @@ -71,31 +83,18 @@ Texture2D GetIconForDependency(Type type, string assetPath)

public override void Draw()
{
//don't draw this section at all if there are no dependencies
if (_dependencyAssets.All(p => p == null))
{
return;
}

LDtkEditorGUIUtility.DrawDivider();
base.Draw();
}

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

if (dependencyAsset == null)
{
continue;
}

using (new LDtkGUIEnabledScope(false))
for (int i = 0; i < _dependencies.Length; i++)
{
EditorGUILayout.ObjectField(_dependencyContent[i], dependencyAsset, typeof(Object), false);
EditorGUILayout.ObjectField(_dependencyContent[i], _dependencyAssets[i], typeof(Object), false);
}
}
}
Expand Down

0 comments on commit 82b5aa1

Please sign in to comment.