【图片压缩工具】
parent
37381da67e
commit
eb452a1c69
|
@ -343,6 +343,251 @@ namespace LJ_OptTools
|
||||||
GameEditor.CustomImportSettings.enabled = false;
|
GameEditor.CustomImportSettings.enabled = false;
|
||||||
EditorUtility.ClearProgressBar();
|
EditorUtility.ClearProgressBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region 图片压缩
|
||||||
|
[MenuItem("Assets/图片压缩/UITextue")]
|
||||||
|
public static void UITexture()
|
||||||
|
{
|
||||||
|
DoCompress(0);
|
||||||
|
}
|
||||||
|
[MenuItem("Assets/图片压缩/BGSingle")]
|
||||||
|
public static void BGSingle()
|
||||||
|
{
|
||||||
|
DoCompress(1);
|
||||||
|
}
|
||||||
|
[MenuItem("Assets/图片压缩/BGMultiple")]
|
||||||
|
public static void BGMultiple()
|
||||||
|
{
|
||||||
|
DoCompress(2);
|
||||||
|
}
|
||||||
|
[MenuItem("Assets/图片压缩/SpineTexture")]
|
||||||
|
public static void SpineTexture()
|
||||||
|
{
|
||||||
|
DoCompress(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void DoCompress(int cType)
|
||||||
|
{
|
||||||
|
var guids = Selection.assetGUIDs;
|
||||||
|
var filePaths = new List<string>();
|
||||||
|
foreach (var id in guids)
|
||||||
|
{
|
||||||
|
var path = AssetDatabase.GUIDToAssetPath(id);
|
||||||
|
if (File.Exists(path))
|
||||||
|
{
|
||||||
|
if (!filePaths.Contains(path))
|
||||||
|
filePaths.Add(path);
|
||||||
|
}
|
||||||
|
else if (Directory.Exists(path))
|
||||||
|
{
|
||||||
|
var subFileGuids = AssetDatabase.FindAssets("t:Texture", new string[] { path });
|
||||||
|
if (subFileGuids != null && subFileGuids.Length > 0)
|
||||||
|
{
|
||||||
|
foreach (var subId in subFileGuids)
|
||||||
|
{
|
||||||
|
var subPath = AssetDatabase.GUIDToAssetPath(subId);
|
||||||
|
if (!filePaths.Contains(subPath))
|
||||||
|
filePaths.Add(subPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filePaths.Count < 1) return;
|
||||||
|
for (int i = 0; i < filePaths.Count; i++)
|
||||||
|
{
|
||||||
|
string path = filePaths[i];
|
||||||
|
EditorUtility.DisplayProgressBar(string.Format("Opt UI Texture({0}/{1})", i, filePaths.Count), path, i * 1f / filePaths.Count);
|
||||||
|
TextureImporter ti = (TextureImporter)TextureImporter.GetAtPath(path);
|
||||||
|
switch (cType)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
SetUITexture(ti);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
SetBGSingle(ti);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
SetBGMultiple(ti);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
SetSpineTexture(ti);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
AssetDatabase.ImportAsset(path);
|
||||||
|
}
|
||||||
|
EditorUtility.ClearProgressBar();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设置UI图片自动图集名称,与图片格式
|
||||||
|
/// </summary>
|
||||||
|
///
|
||||||
|
public static string GetAtlasName(string assetPath)
|
||||||
|
{
|
||||||
|
int index = assetPath.IndexOf("/Atlas/");
|
||||||
|
string atlasName = assetPath.Substring(index + 7);
|
||||||
|
index = atlasName.IndexOf("/");
|
||||||
|
if (index != -1)
|
||||||
|
{
|
||||||
|
atlasName = atlasName.Substring(0, index);
|
||||||
|
}
|
||||||
|
return atlasName;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void SetUITexture(TextureImporter importer)
|
||||||
|
{
|
||||||
|
importer.spritePackingTag = GetAtlasName(importer.assetPath);
|
||||||
|
|
||||||
|
TextureImporterSettings importerSettings = new TextureImporterSettings();
|
||||||
|
importer.ReadTextureSettings(importerSettings);
|
||||||
|
importerSettings.npotScale = TextureImporterNPOTScale.None;
|
||||||
|
importerSettings.spriteMode = 1;//Single
|
||||||
|
importerSettings.spritePixelsPerUnit = GameLogic.AppConst.PIXELTOWORLD;
|
||||||
|
importerSettings.mipmapEnabled = false;
|
||||||
|
importerSettings.wrapMode = TextureWrapMode.Clamp;
|
||||||
|
importerSettings.filterMode = FilterMode.Trilinear;
|
||||||
|
importerSettings.alphaIsTransparency = true;
|
||||||
|
importer.SetTextureSettings(importerSettings);
|
||||||
|
|
||||||
|
//Android
|
||||||
|
TextureImporterPlatformSettings s_Android = new TextureImporterPlatformSettings();
|
||||||
|
s_Android.name = "Android";
|
||||||
|
s_Android.maxTextureSize = 2048;
|
||||||
|
s_Android.format = TextureImporterFormat.ETC2_RGBA8Crunched;
|
||||||
|
s_Android.compressionQuality = 50;
|
||||||
|
s_Android.allowsAlphaSplitting = false;
|
||||||
|
s_Android.overridden = true;
|
||||||
|
importer.SetPlatformTextureSettings(s_Android);
|
||||||
|
|
||||||
|
//IOS
|
||||||
|
TextureImporterPlatformSettings s_IOS = new TextureImporterPlatformSettings();
|
||||||
|
s_IOS.name = "iPhone";
|
||||||
|
s_IOS.maxTextureSize = 2048;
|
||||||
|
s_IOS.format = TextureImporterFormat.PVRTC_RGBA4;
|
||||||
|
s_IOS.compressionQuality = 50;
|
||||||
|
s_IOS.allowsAlphaSplitting = false;
|
||||||
|
s_IOS.overridden = true;
|
||||||
|
importer.SetPlatformTextureSettings(s_IOS);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void SetBGSingle(TextureImporter importer)
|
||||||
|
{
|
||||||
|
importer.spritePackingTag = string.Empty;
|
||||||
|
|
||||||
|
TextureImporterSettings importerSettings = new TextureImporterSettings();
|
||||||
|
importer.ReadTextureSettings(importerSettings);
|
||||||
|
importerSettings.npotScale = TextureImporterNPOTScale.None;
|
||||||
|
importerSettings.spriteMode = 1;//Single
|
||||||
|
importerSettings.spritePixelsPerUnit = GameLogic.AppConst.PIXELTOWORLD;
|
||||||
|
importerSettings.mipmapEnabled = false;
|
||||||
|
importerSettings.wrapMode = TextureWrapMode.Clamp;
|
||||||
|
importerSettings.filterMode = FilterMode.Trilinear;
|
||||||
|
importerSettings.alphaIsTransparency = true;
|
||||||
|
importer.SetTextureSettings(importerSettings);
|
||||||
|
|
||||||
|
//Android
|
||||||
|
TextureImporterPlatformSettings s_Android = new TextureImporterPlatformSettings();
|
||||||
|
s_Android.name = "Android";
|
||||||
|
s_Android.maxTextureSize = 2048;
|
||||||
|
s_Android.format = TextureImporterFormat.ETC2_RGBA8Crunched;
|
||||||
|
s_Android.compressionQuality = 50;
|
||||||
|
s_Android.allowsAlphaSplitting = false;
|
||||||
|
s_Android.overridden = true;
|
||||||
|
importer.SetPlatformTextureSettings(s_Android);
|
||||||
|
|
||||||
|
//IOS
|
||||||
|
TextureImporterPlatformSettings s_IOS = new TextureImporterPlatformSettings();
|
||||||
|
s_IOS.name = "iPhone";
|
||||||
|
s_IOS.maxTextureSize = 2048;
|
||||||
|
s_IOS.format = TextureImporterFormat.ASTC_RGBA_8x8;
|
||||||
|
s_IOS.compressionQuality = 50;
|
||||||
|
s_IOS.allowsAlphaSplitting = false;
|
||||||
|
s_IOS.overridden = true;
|
||||||
|
importer.SetPlatformTextureSettings(s_IOS);
|
||||||
|
}
|
||||||
|
static void SetBGMultiple(TextureImporter importer)
|
||||||
|
{
|
||||||
|
importer.spritePackingTag = string.Empty;
|
||||||
|
|
||||||
|
TextureImporterSettings importerSettings = new TextureImporterSettings();
|
||||||
|
importer.ReadTextureSettings(importerSettings);
|
||||||
|
importerSettings.npotScale = TextureImporterNPOTScale.None;
|
||||||
|
importerSettings.spriteMode = 2;//Multiple
|
||||||
|
importerSettings.spritePixelsPerUnit = GameLogic.AppConst.PIXELTOWORLD;
|
||||||
|
importerSettings.mipmapEnabled = false;
|
||||||
|
importerSettings.wrapMode = TextureWrapMode.Clamp;
|
||||||
|
importerSettings.filterMode = FilterMode.Trilinear;
|
||||||
|
importerSettings.alphaIsTransparency = true;
|
||||||
|
importer.SetTextureSettings(importerSettings);
|
||||||
|
|
||||||
|
//Android
|
||||||
|
TextureImporterPlatformSettings s_Android = new TextureImporterPlatformSettings();
|
||||||
|
s_Android.name = "Android";
|
||||||
|
s_Android.maxTextureSize = 2048;
|
||||||
|
s_Android.format = TextureImporterFormat.ETC2_RGBA8Crunched;
|
||||||
|
s_Android.compressionQuality = 50;
|
||||||
|
s_Android.allowsAlphaSplitting = false;
|
||||||
|
s_Android.overridden = true;
|
||||||
|
importer.SetPlatformTextureSettings(s_Android);
|
||||||
|
|
||||||
|
//IOS
|
||||||
|
TextureImporterPlatformSettings s_IOS = new TextureImporterPlatformSettings();
|
||||||
|
s_IOS.name = "iPhone";
|
||||||
|
s_IOS.maxTextureSize = 2048;
|
||||||
|
s_IOS.format = TextureImporterFormat.ASTC_RGBA_8x8;
|
||||||
|
s_IOS.compressionQuality = 50;
|
||||||
|
s_IOS.allowsAlphaSplitting = false;
|
||||||
|
s_IOS.overridden = true;
|
||||||
|
importer.SetPlatformTextureSettings(s_IOS);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void SetSpineTexture(TextureImporter importer)
|
||||||
|
{
|
||||||
|
importer.spritePackingTag = string.Empty;
|
||||||
|
|
||||||
|
TextureImporterSettings importerSettings = new TextureImporterSettings();
|
||||||
|
importer.ReadTextureSettings(importerSettings);
|
||||||
|
importerSettings.npotScale = TextureImporterNPOTScale.None;
|
||||||
|
importerSettings.spriteMode = 1;//Single
|
||||||
|
importerSettings.spritePixelsPerUnit = GameLogic.AppConst.PIXELTOWORLD;
|
||||||
|
importerSettings.mipmapEnabled = false;
|
||||||
|
importerSettings.wrapMode = TextureWrapMode.Clamp;
|
||||||
|
importerSettings.filterMode = FilterMode.Trilinear;
|
||||||
|
importerSettings.alphaIsTransparency = true;
|
||||||
|
importer.SetTextureSettings(importerSettings);
|
||||||
|
|
||||||
|
//Android
|
||||||
|
TextureImporterPlatformSettings s_Android = new TextureImporterPlatformSettings();
|
||||||
|
s_Android.name = "Android";
|
||||||
|
s_Android.maxTextureSize = 2048;
|
||||||
|
s_Android.format = TextureImporterFormat.ASTC_RGBA_5x5;
|
||||||
|
s_Android.compressionQuality = 50;
|
||||||
|
s_Android.allowsAlphaSplitting = false;
|
||||||
|
s_Android.overridden = true;
|
||||||
|
importer.SetPlatformTextureSettings(s_Android);
|
||||||
|
|
||||||
|
//IOS
|
||||||
|
TextureImporterPlatformSettings s_IOS = new TextureImporterPlatformSettings();
|
||||||
|
s_IOS.name = "iPhone";
|
||||||
|
s_IOS.maxTextureSize = 2048;
|
||||||
|
s_IOS.format = TextureImporterFormat.ASTC_RGBA_5x5;
|
||||||
|
s_IOS.compressionQuality = 50;
|
||||||
|
s_IOS.allowsAlphaSplitting = false;
|
||||||
|
s_IOS.overridden = true;
|
||||||
|
importer.SetPlatformTextureSettings(s_IOS);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue