| | |
| | | static string rootPath = Application.dataPath + "/ResourcesOut/Sprite";
|
| | | static string spriteRelativePath = "Assets/ResourcesOut/Sprite";
|
| | |
|
| | | /// <summary>
|
| | | /// 图集处理流程的重入保护:流程内部会大量 SaveAndReimport / ImportAsset,
|
| | | /// 这些都会触发 AssetPostprocessor,若不挡住重入就会与批处理/菜单触发形成互相导入。
|
| | | /// </summary>
|
| | | private static bool s_IsRunning;
|
| | |
|
| | | [MenuItem("程序/Sprite/标准化Sprite设置")]
|
| | | public static void UpdateAllSpritePackingSetting()
|
| | | {
|
| | | if (s_IsRunning)
|
| | | {
|
| | | Debug.LogWarning("[SpritePack] 上一次图集处理尚未结束,已跳过本次调用");
|
| | | return;
|
| | | }
|
| | |
|
| | | s_IsRunning = true;
|
| | | try
|
| | | {
|
| | | UpdateAllSpritePackingSettingInternal();
|
| | | }
|
| | | finally
|
| | | {
|
| | | s_IsRunning = false;
|
| | | EditorUtility.ClearProgressBar();
|
| | | }
|
| | | }
|
| | |
|
| | | private static void UpdateAllSpritePackingSettingInternal()
|
| | | {
|
| | | var path = "Assets/Editor/SpritePacking/SpriteSettings.asset";
|
| | | var so = AssetDatabase.LoadAssetAtPath<SpriteSettingConfig>(path);
|
| | |
| | |
|
| | | EditorUtility.ClearProgressBar();
|
| | |
|
| | | SpritePack();
|
| | | SpritePackInternal();
|
| | | }
|
| | |
|
| | | [MenuItem("程序/Sprite/打包BuiltIn图集")]
|
| | |
| | | }
|
| | | };
|
| | | spriteAtlas = CreateSpriteAtlas(spriteRelativePath_BuiltIn, setting);
|
| | | if (spriteAtlas == null)
|
| | | {
|
| | | Debug.LogError($"[SpritePack] 创建 BuiltIn 图集失败: {builtInSpritePath}");
|
| | | return;
|
| | | }
|
| | | }
|
| | | List<string> excludePngs = new List<string>() { "Launch_1.png", "Launch_2.png", "Launch_3.png", "LoginBackGround.png", "TB_DL_Logo.png" };
|
| | |
|
| | |
| | |
|
| | | [MenuItem("程序/Sprite/打包图集")]
|
| | | public static void SpritePack()
|
| | | {
|
| | | if (s_IsRunning)
|
| | | {
|
| | | Debug.LogWarning("[SpritePack] 上一次图集处理尚未结束,已跳过本次调用");
|
| | | return;
|
| | | }
|
| | |
|
| | | s_IsRunning = true;
|
| | | try
|
| | | {
|
| | | SpritePackInternal();
|
| | | }
|
| | | finally
|
| | | {
|
| | | s_IsRunning = false;
|
| | | EditorUtility.ClearProgressBar();
|
| | | }
|
| | | }
|
| | |
|
| | | private static void SpritePackInternal()
|
| | | {
|
| | | var path = "Assets/Editor/SpritePacking/SpriteSettings.asset";
|
| | | var so = AssetDatabase.LoadAssetAtPath<SpriteSettingConfig>(path);
|
| | |
| | | if (spriteAtlas == null)
|
| | | {
|
| | | spriteAtlas = CreateSpriteAtlas(spriteRelativePath, setting);
|
| | | if (spriteAtlas == null)
|
| | | {
|
| | | Debug.LogError($"[SpritePack] 创建图集失败: {filePath}");
|
| | | continue;
|
| | | }
|
| | | }
|
| | |
|
| | | string spriteFilePath = rootPath + "/" + spritefilePathName;
|
| | |
| | | string atlasPath = outPath + "/" + setting.folderName + ".spriteatlasv2";
|
| | | CreateEmptySpriteAtlas(atlasPath);
|
| | |
|
| | | |
| | | SpriteAtlasImporter atlasImporter = SpriteAtlasImporter.GetAtPath(atlasPath) as SpriteAtlasImporter;
|
| | | if (atlasImporter == null)
|
| | | {
|
| | | Debug.LogError($"[SpritePack] 获取 SpriteAtlasImporter 失败: {atlasPath}");
|
| | | return null;
|
| | | }
|
| | |
|
| | | #region 图集基础设置
|
| | |
|
| | |
| | | {
|
| | | SpriteAtlasAsset.Save(new SpriteAtlasAsset(), atlasPath);
|
| | | AssetDatabase.SaveAssets();
|
| | | AssetDatabase.Refresh();
|
| | |
|
| | | // 这里只能用精确导入,不能调用 AssetDatabase.Refresh():
|
| | | // 全库刷新会把刚写入的图集再次推入导入流程,进而触发 OnPostprocessAllAssets,
|
| | | // 被 Unity 判定为 "infinite import loop"(ZZBF.spriteatlasv2 反复 changed)。
|
| | | AssetDatabase.ImportAsset(atlasPath, ImportAssetOptions.ForceSynchronousImport);
|
| | | }
|
| | |
|
| | |
|
| | |
| | | FileName(spriteFilePath, excludePng);
|
| | |
|
| | | SpriteAtlas spriteAtlasTmp = AssetDatabase.LoadAssetAtPath(filePath, typeof(UnityEngine.Object)) as SpriteAtlas;
|
| | | if (spriteAtlasTmp == null)
|
| | | {
|
| | | Debug.LogError($"[SpritePack] 无法加载图集,跳过更新: {filePath}");
|
| | | return;
|
| | | }
|
| | |
|
| | | // 获取图集下图片
|
| | | List<UnityEngine.Object> packables = new List<UnityEngine.Object>(spriteAtlasTmp.GetPackables());
|