From 631f42bbccb190a6ff08e26a3c29e85df5501702 Mon Sep 17 00:00:00 2001 From: Cameron Date: Mon, 28 Aug 2023 00:35:33 -0700 Subject: [PATCH] better tileset initialization in some minor cases --- .../Editor/ScriptedImporter/LDtkPpuInitializer.cs | 10 ++++++++-- .../Editor/ScriptedImporter/LDtkProjectImporter.cs | 4 ++-- .../Editor/ScriptedImporter/LDtkTilesetImporter.cs | 4 ++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Assets/LDtkUnity/Editor/ScriptedImporter/LDtkPpuInitializer.cs b/Assets/LDtkUnity/Editor/ScriptedImporter/LDtkPpuInitializer.cs index 6ffa6cdd5..9342c5446 100644 --- a/Assets/LDtkUnity/Editor/ScriptedImporter/LDtkPpuInitializer.cs +++ b/Assets/LDtkUnity/Editor/ScriptedImporter/LDtkPpuInitializer.cs @@ -5,13 +5,15 @@ namespace LDtkUnity.Editor { internal struct LDtkPpuInitializer { + public string ImporterPath; public string ProjectPath; public int PixelsPerUnit; - public LDtkPpuInitializer(int ppu, string projectPath) + public LDtkPpuInitializer(int ppu, string projectPath, string importerPath) { PixelsPerUnit = ppu; ProjectPath = projectPath; + ImporterPath = importerPath; } public bool OnResetImporter() @@ -23,7 +25,11 @@ public bool OnResetImporter() } int defaultGridSize = -1; - if (!LDtkJsonDigger.GetDefaultGridSize(ProjectPath, ref defaultGridSize)) + if (ImporterPath != ProjectPath && AssetImporter.GetAtPath(ProjectPath) is LDtkProjectImporter projectImporter) + { + defaultGridSize = projectImporter.PixelsPerUnit; + } + else if (!LDtkJsonDigger.GetDefaultGridSize(ProjectPath, ref defaultGridSize)) { //if problem, then default to what LDtk also defaults to upon a new project defaultGridSize = LDtkImporterConsts.DEFAULT_PPU; diff --git a/Assets/LDtkUnity/Editor/ScriptedImporter/LDtkProjectImporter.cs b/Assets/LDtkUnity/Editor/ScriptedImporter/LDtkProjectImporter.cs index 96c53cfa6..1aa1508c4 100644 --- a/Assets/LDtkUnity/Editor/ScriptedImporter/LDtkProjectImporter.cs +++ b/Assets/LDtkUnity/Editor/ScriptedImporter/LDtkProjectImporter.cs @@ -88,7 +88,7 @@ internal sealed class LDtkProjectImporter : LDtkJsonImporter //this will run upon standard reset, but also upon the meta file generation during the first import private void Reset() { - LDtkPpuInitializer ppu = new LDtkPpuInitializer(_pixelsPerUnit, assetPath); + LDtkPpuInitializer ppu = new LDtkPpuInitializer(_pixelsPerUnit, assetPath, assetPath); if (ppu.OnResetImporter()) { _pixelsPerUnit = ppu.PixelsPerUnit; @@ -149,7 +149,7 @@ protected override void Import() //if for whatever reason (or backwards compatibility), if the ppu is -1 in any capacity Profiler.BeginSample("SetPixelsPerUnit"); - LDtkPpuInitializer ppu = new LDtkPpuInitializer(_pixelsPerUnit, assetPath); + LDtkPpuInitializer ppu = new LDtkPpuInitializer(_pixelsPerUnit, assetPath, assetPath); if (ppu.TryInitializePixelsPerUnit(json.DefaultGridSize)) { _pixelsPerUnit = ppu.PixelsPerUnit; diff --git a/Assets/LDtkUnity/Editor/ScriptedImporter/LDtkTilesetImporter.cs b/Assets/LDtkUnity/Editor/ScriptedImporter/LDtkTilesetImporter.cs index e9fc39c0e..5d169c2fa 100644 --- a/Assets/LDtkUnity/Editor/ScriptedImporter/LDtkTilesetImporter.cs +++ b/Assets/LDtkUnity/Editor/ScriptedImporter/LDtkTilesetImporter.cs @@ -64,7 +64,7 @@ internal sealed partial class LDtkTilesetImporter : LDtkJsonImporter