unity修炼之路Unity技术分享Unity编辑器开发分享

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

2016-05-13  本文已影响251人  霸俊流年

关键代码如下

    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();
    }
上一篇 下一篇

猜你喜欢

热点阅读