一鍵恢復安卓貼圖壓縮格式到初始狀態

  • 因為美術之前修改資源的習慣,手上的安卓的貼圖資源大部分都被修改為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();
    }
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容