| | |
| | | private static readonly string TARGET_FOLDER = TexturePlatformFormatHelper.TARGET_FOLDER; |
| | | private static readonly bool AUTO_APPLY_ATLAS_SETTINGS = true; |
| | | |
| | | /// <summary> |
| | | /// 防止回调中 SaveAndReimport 同步触发下一次 OnPostprocessAllAssets 造成嵌套重入。 |
| | | /// </summary> |
| | | private static bool s_IsApplying; |
| | | |
| | | void OnPreprocessTexture() |
| | | { |
| | | if (!assetPath.StartsWith(TARGET_FOLDER)) |
| | |
| | | { |
| | | if (!AUTO_APPLY_ATLAS_SETTINGS) |
| | | return; |
| | | // 回调里的 SaveAndReimport 会同步再次触发本回调,必须挡掉,否则会无限自触发 |
| | | if (s_IsApplying) |
| | | return; |
| | | |
| | | foreach (var assetPath in importedAssets) |
| | | s_IsApplying = true; |
| | | try |
| | | { |
| | | if (!assetPath.StartsWith(TARGET_FOLDER)) |
| | | continue; |
| | | if (!assetPath.EndsWith(".spriteatlasv2") && !assetPath.EndsWith(".spriteatlas")) |
| | | continue; |
| | | |
| | | try |
| | | foreach (var assetPath in importedAssets) |
| | | { |
| | | var importer = SpriteAtlasImporter.GetAtPath(assetPath) as SpriteAtlasImporter; |
| | | if (importer == null) |
| | | if (!assetPath.StartsWith(TARGET_FOLDER)) |
| | | continue; |
| | | if (!assetPath.EndsWith(".spriteatlasv2") && !assetPath.EndsWith(".spriteatlas")) |
| | | continue; |
| | | |
| | | if (TexturePlatformFormatHelper.ApplyAtlasPlatformSettings(importer)) |
| | | try |
| | | { |
| | | importer.SaveAndReimport(); |
| | | Debug.Log($"[TexImport] 图集: {assetPath}"); |
| | | var importer = SpriteAtlasImporter.GetAtPath(assetPath) as SpriteAtlasImporter; |
| | | if (importer == null) |
| | | continue; |
| | | |
| | | if (TexturePlatformFormatHelper.ApplyAtlasPlatformSettings(importer)) |
| | | { |
| | | importer.SaveAndReimport(); |
| | | Debug.Log($"[TexImport] 图集: {assetPath}"); |
| | | } |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | Debug.LogError($"[TexImport] 图集失败 {assetPath}: {ex.Message}"); |
| | | } |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | Debug.LogError($"[TexImport] 图集失败 {assetPath}: {ex.Message}"); |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | s_IsApplying = false; |
| | | } |
| | | } |
| | | } |