因為美術之前修改資源的習慣,手上的安卓的貼圖資源大部分都被修改為DXT的格式.
之前發現小米會過濾掉使用DXT的貼圖的應用,所以寫個小工具把修改過的資源批量修改到默認的格式.
關鍵代碼如下
static void ChangeAndroidTextureFormat()
{
var assets = AssetDatabase.FindAssets("t:Texture");
AssetDatabase.StartAssetEditing();
foreach (var guid in assets)
{
var assetPath = AssetDatabase.GUIDToAssetPath(guid);
var textureImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter;
if (textureImporter== null)
continue;
int maxsize = 0;
TextureImporterFormat textureImporterFormat;
string androidPlatform = "Android";
if (textureImporter.GetPlatformTextureSettings(androidPlatform, out maxsize, out textureImporterFormat))
{
if (textureImporterFormat == TextureImporterFormat.DXT1 || textureImporterFormat == TextureImporterFormat.DXT1Crunched)
{
textureImporter.SetPlatformTextureSettings(androidPlatform, maxsize, TextureImporterFormat.ETC_RGB4);
textureImporter.SaveAndReimport();
}
if (textureImporterFormat == TextureImporterFormat.DXT5 || textureImporterFormat == TextureImporterFormat.DXT5Crunched)
{
textureImporter.SetPlatformTextureSettings(androidPlatform, maxsize, TextureImporterFormat.ETC2_RGBA8);
textureImporter.SaveAndReimport();
}
}
}
AssetDatabase.StopAssetEditing();
AssetDatabase.Refresh();
}