美文网首页unity修炼之路Unity技术分享Unity编辑器开发分享
一键恢复安卓贴图压缩格式到初始状态

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

作者: 霸俊流年 | 来源:发表于2016-05-13 17:51 被阅读251次
    • 因为美术之前修改资源的习惯,手上的安卓的贴图资源大部分都被修改为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();
        }

    相关文章

      网友评论

        本文标题:一键恢复安卓贴图压缩格式到初始状态

        本文链接:https://www.haomeiwen.com/subject/hukmrttx.html