一键恢复安卓贴图压缩格式到初始状态

  • 因为美术之前修改资源的习惯,手上的安卓的贴图资源大部分都被修改为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();
    }

你可能感兴趣的:(一键恢复安卓贴图压缩格式到初始状态)