From d5c61ed998a38d62a03f4d58e4d2fe9516d27ea3 Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期四, 24 九月 2026 14:51:26 +0800
Subject: [PATCH] 自动图集设置
---
Assets/Editor/Tool/UpdateSpritePackingSetting.cs | 45 ++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 40 insertions(+), 5 deletions(-)
diff --git a/Assets/Editor/Tool/UpdateSpritePackingSetting.cs b/Assets/Editor/Tool/UpdateSpritePackingSetting.cs
index a79270c..ab7a208 100644
--- a/Assets/Editor/Tool/UpdateSpritePackingSetting.cs
+++ b/Assets/Editor/Tool/UpdateSpritePackingSetting.cs
@@ -58,6 +58,18 @@
{
continue;
}
+
+ int sourceWidth;
+ int sourceHeight;
+ textureImporter.GetSourceTextureWidthAndHeight(out sourceWidth, out sourceHeight);
+ if (sourceWidth > TexturePlatformFormatHelper.ATLAS_MAX_SIZE
+ || sourceHeight > TexturePlatformFormatHelper.ATLAS_MAX_SIZE)
+ {
+ count++;
+ EditorUtility.DisplayProgressBar(StringUtility.Concat("璁剧疆鍥鹃泦鏍囩:", setting.folderName), file.Name, count / (float)total);
+ continue;
+ }
+
bool isChange = false;
if (textureImporter.textureType != TextureImporterType.Sprite)
{
@@ -125,14 +137,14 @@
new SpriteSettingConfig.PlatformSetting()
{
name = "Android",
- maxTextureSize = 2048,
+ maxTextureSize = TexturePlatformFormatHelper.ATLAS_MAX_SIZE,
textureCompression = TextureImporterCompression.Compressed,
textureFormat = TextureImporterFormat.ASTC_6x6
},
new SpriteSettingConfig.PlatformSetting()
{
name = "iPhone",
- maxTextureSize = 2048,
+ maxTextureSize = TexturePlatformFormatHelper.ATLAS_MAX_SIZE,
textureCompression = TextureImporterCompression.Compressed,
textureFormat = TextureImporterFormat.ASTC_6x6
}
@@ -256,7 +268,7 @@
{
TextureImporterPlatformSettings settingPlatform = atlasImporter.GetPlatformSettings(platformSetting.name);
settingPlatform.overridden = true;
- settingPlatform.maxTextureSize = platformSetting.maxTextureSize;
+ settingPlatform.maxTextureSize = TexturePlatformFormatHelper.ATLAS_MAX_SIZE;
settingPlatform.textureCompression = platformSetting.textureCompression;
settingPlatform.format = platformSetting.textureFormat;
atlasImporter.SetPlatformSettings(settingPlatform);
@@ -303,9 +315,28 @@
List<UnityEngine.Object> objectsForPack = new List<UnityEngine.Object>();
foreach (string item in textureFullName)
{
- // 鍔犺浇鎸囧畾鐩綍
+ var textureImporter = AssetImporter.GetAtPath(item) as TextureImporter;
+ if (textureImporter == null
+ || textureImporter.textureType != TextureImporterType.Sprite
+ || textureImporter.spriteImportMode == SpriteImportMode.None)
+ {
+ continue;
+ }
+
+ int sourceWidth;
+ int sourceHeight;
+ textureImporter.GetSourceTextureWidthAndHeight(out sourceWidth, out sourceHeight);
+ if (sourceWidth > TexturePlatformFormatHelper.ATLAS_MAX_SIZE
+ || sourceHeight > TexturePlatformFormatHelper.ATLAS_MAX_SIZE)
+ {
+ Debug.LogWarning($"[SpritePack] 璺宠繃瓒呰繃 {TexturePlatformFormatHelper.ATLAS_MAX_SIZE} 鐨勮创鍥�: {item} ({sourceWidth}x{sourceHeight})");
+ continue;
+ }
+
UnityEngine.Object spriteObj = AssetDatabase.LoadAssetAtPath(item, typeof(UnityEngine.Object));
- //Debug.Log("瀛榩ng鍜宩pg鍚庣紑鐨勫浘鐗�: " + item + " , " + !packables.Contains(spriteObj));
+ if (spriteObj == null)
+ continue;
+
if (!packables.Contains(spriteObj))
{
atlas.Add(new UnityEngine.Object[] { spriteObj });
@@ -324,6 +355,10 @@
SpriteAtlasAsset.Save(atlas, filePath);
+
+ var atlasImporter = SpriteAtlasImporter.GetAtPath(filePath) as SpriteAtlasImporter;
+ if (atlasImporter != null && TexturePlatformFormatHelper.ApplyAtlasMaxTextureSize(atlasImporter))
+ atlasImporter.SaveAndReimport();
}
/// <summary>
--
Gitblit v1.8.0