From 51497d37d2ea18aa4e439250119bb6f01224f519 Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期五, 25 九月 2026 13:29:41 +0800
Subject: [PATCH] 0312 修复图集死循环问题
---
Assets/Editor/Tool/TexturePlatformAssetPostprocessor.cs | 48 ++++++++++++++++++++++++++++++++----------------
1 files changed, 32 insertions(+), 16 deletions(-)
diff --git a/Assets/Editor/Tool/TexturePlatformAssetPostprocessor.cs b/Assets/Editor/Tool/TexturePlatformAssetPostprocessor.cs
index 2e8fafd..f326495 100644
--- a/Assets/Editor/Tool/TexturePlatformAssetPostprocessor.cs
+++ b/Assets/Editor/Tool/TexturePlatformAssetPostprocessor.cs
@@ -15,6 +15,11 @@
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))
@@ -38,30 +43,41 @@
{
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;
}
}
}
--
Gitblit v1.8.0