Skip to content

Commit

Permalink
error handle for if the aseprite file failed to import or did not gen…
Browse files Browse the repository at this point in the history
…erate a sprite
  • Loading branch information
Cammin committed Oct 3, 2023
1 parent fbf90ee commit b2fc711
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
24 changes: 14 additions & 10 deletions Assets/LDtkUnity/Editor/ScriptedImporter/LDtkTilesetImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,12 @@ protected override void Import()
Profiler.EndSample();

Profiler.BeginSample("PrepareGenerate");
TextureGenerationOutput output = PrepareGenerate(platformSettings);
if (!PrepareGenerate(platformSettings, out TextureGenerationOutput output))
{
FailImport();
Profiler.EndSample();
return;
}
Profiler.EndSample();

Texture2D outputTexture = output.texture;
Expand Down Expand Up @@ -365,10 +370,8 @@ private static void TilemapColliderTileUpdate()
};
}

private TextureGenerationOutput PrepareGenerate(TextureImporterPlatformSettings platformSettings)
private bool PrepareGenerate(TextureImporterPlatformSettings platformSettings, out TextureGenerationOutput output)
{


Debug.Assert(_pixelsPerUnit > 0, $"_pixelsPerUnit was {_pixelsPerUnit}");

TextureImporterSettings importerSettings = new TextureImporterSettings();
Expand Down Expand Up @@ -396,8 +399,9 @@ private TextureGenerationOutput PrepareGenerate(TextureImporterPlatformSettings
Sprite sprite = AssetDatabase.LoadAssetAtPath<Sprite>(PathToTexture(assetPath));
if (sprite == null)
{
FailImport();

output = default;
Logger.LogError($"Failed to load the aseprite sprite for \"{AssetName}\". Either the Aseprite file failed to import, or the aseprite file's import settings are configured to not generate a sprite.");
return false;
}

Profiler.BeginSample("GenerateAsepriteTexture");
Expand All @@ -422,15 +426,15 @@ private TextureGenerationOutput PrepareGenerate(TextureImporterPlatformSettings
Profiler.EndSample();

Profiler.BeginSample("TextureGeneration.Generate");
TextureGenerationOutput output = TextureGeneration.Generate(
output = TextureGeneration.Generate(
ImportContext, rawData, copy.width, copy.height, _sprites.Concat(_additionalTiles).ToArray(),
platformSettings, importerSettings, string.Empty, _secondaryTextures);
Profiler.EndSample();

return output;
return true;
}

public Texture2D GenerateTextureFromAseprite(Sprite sprite)
private Texture2D GenerateTextureFromAseprite(Sprite sprite)
{
Texture2D croppedTexture = new Texture2D(_json.PxWid, _json.PxHei, TextureFormat.RGBA32, false, false);

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b2fc711

Please sign in to comment.