diff --git a/Assets/_DDD/_Scripts/AssetPostprocessors/AssetPostprocessorSprite.cs b/Assets/_DDD/_Scripts/AssetPostprocessors/AssetPostprocessorSprite.cs index aa7773680..1c4c17d5e 100644 --- a/Assets/_DDD/_Scripts/AssetPostprocessors/AssetPostprocessorSprite.cs +++ b/Assets/_DDD/_Scripts/AssetPostprocessors/AssetPostprocessorSprite.cs @@ -203,6 +203,13 @@ public static void CreateAtlas(string path, string destPath) if (objects.Count == 0) return; + // Validate destination path extension + if (!destPath.EndsWith(ExtenstionConstants.SpriteAtlasExtenstionLower, System.StringComparison.OrdinalIgnoreCase)) + { + Debug.LogWarning($"[SpriteAtlas] destPath must end with .spriteatlas : {destPath}"); + return; + } + Utils.MakeFolderFromFilePath(destPath); var atlas = new SpriteAtlasAsset(); @@ -216,9 +223,17 @@ public static void CreateAtlas(string path, string destPath) atlas.Add(objects.ToArray()); SpriteAtlasAsset.Save(atlas, destPath); - AssetDatabase.Refresh(); - var sai = (SpriteAtlasImporter)AssetImporter.GetAtPath(destPath); + // Ensure importer is created/applied synchronously before accessing it + AssetDatabase.ImportAsset(destPath, ImportAssetOptions.ForceUpdate | ImportAssetOptions.ForceSynchronousImport); + + var sai = AssetImporter.GetAtPath(destPath) as SpriteAtlasImporter; + if (sai == null) + { + Debug.LogWarning($"[SpriteAtlas] Importer not ready for '{destPath}'. Skipping settings this pass."); + return; + } + sai.packingSettings = new SpriteAtlasPackingSettings { enableRotation = false, @@ -235,8 +250,11 @@ public static void CreateAtlas(string path, string destPath) generateMipMaps = false }; - // 저장 후 설정 반영을 위해 동기 임포트, 그리고 즉시 패킹 수행 + // Persist settings and reimport synchronously to apply them + AssetDatabase.WriteImportSettingsIfDirty(destPath); AssetDatabase.ImportAsset(destPath, ImportAssetOptions.ForceUpdate | ImportAssetOptions.ForceSynchronousImport); + + // Finally, pack the atlas for the active build target var packedAtlas = AssetDatabase.LoadAssetAtPath(destPath); if (packedAtlas != null) { @@ -253,10 +271,22 @@ public static void CreateSingleAtlas(string path, string destPath) AssetDatabase.DeleteAsset(destPath); } + // Validate destination path extension + if (!destPath.EndsWith(ExtenstionConstants.SpriteAtlasExtenstionLower, System.StringComparison.OrdinalIgnoreCase)) + { + Debug.LogWarning($"[SpriteAtlas] destPath must end with .spriteatlas : {destPath}"); + return; + } + Utils.MakeFolderFromFilePath(destPath); var atlas = new SpriteAtlasAsset(); var sprite = AssetDatabase.LoadAssetAtPath(path); + if (sprite == null) + { + Debug.LogWarning($"[SpriteAtlas] Source sprite not found at '{path}'. Skipping atlas: '{destPath}'"); + return; + } atlas.Add(new Object[] { sprite }); var spriteAtlasComponents = new List(); @@ -267,9 +297,17 @@ public static void CreateSingleAtlas(string path, string destPath) } SpriteAtlasAsset.Save(atlas, destPath); - AssetDatabase.Refresh(); - var sai = (SpriteAtlasImporter)AssetImporter.GetAtPath(destPath); + // Ensure importer is created/applied synchronously before accessing it + AssetDatabase.ImportAsset(destPath, ImportAssetOptions.ForceUpdate | ImportAssetOptions.ForceSynchronousImport); + + var sai = AssetImporter.GetAtPath(destPath) as SpriteAtlasImporter; + if (sai == null) + { + Debug.LogWarning($"[SpriteAtlas] Importer not ready for '{destPath}'. Skipping settings this pass."); + return; + } + sai.packingSettings = new SpriteAtlasPackingSettings { enableRotation = false, @@ -286,8 +324,11 @@ public static void CreateSingleAtlas(string path, string destPath) generateMipMaps = false }; - // 저장 후 설정 반영을 위해 동기 임포트, 그리고 즉시 패킹 수행 + // Persist settings and reimport synchronously to apply them + AssetDatabase.WriteImportSettingsIfDirty(destPath); AssetDatabase.ImportAsset(destPath, ImportAssetOptions.ForceUpdate | ImportAssetOptions.ForceSynchronousImport); + + // Finally, pack the atlas for the active build target var packedAtlas = AssetDatabase.LoadAssetAtPath(destPath); if (packedAtlas != null) {