找回密码
 立即注册
查看: 350|回复: 0

Unity检查当前文件夹图片压缩格式(ASTC,ETC等)

[复制链接]
发表于 2021-12-7 16:26 | 显示全部楼层 |阅读模式
using System.Collections;using System.Collections.Generic;using System.IO;using UnityEditor;using UnityEngine;public class TextureAutoSet : EditorWindow{        [MenuItem("Assets/检查图片压缩格式", priority = 0)]    static void AutoSetASTC()    {        string[] guidArray = Selection.assetGUIDs;        Debug.Log(guidArray.Length);        foreach (var item in guidArray)        {            string selectFloder = AssetDatabase.GUIDToAssetPath(item);            DirectoryInfo root = new DirectoryInfo(selectFloder);            GetFloder(root);        }    }    static void GetFloder(DirectoryInfo root)    {        GetFile(root);        //查找子文件夹        DirectoryInfo[] array = root.GetDirectories();        foreach (DirectoryInfo item in array)        {            GetFloder(item);        }    }    static void GetFile(DirectoryInfo root)    {        //DirectoryInfo root = new DirectoryInfo(path);        FileInfo[] fileDic = root.GetFiles();        foreach (var file in fileDic)        {            //sDebug.Log(file);            if (file.FullName.EndsWith(".png") || file.FullName.EndsWith(".jpg") || file.FullName.EndsWith(".tga") ||                file.FullName.EndsWith(".psd") || file.FullName.EndsWith(".PSD") || file.FullName.EndsWith(".exr") ||                file.FullName.EndsWith(".tif"))            {                //Debug.Log("-------------" + file.FullName);                //Debug.Log(Application.dataPath);                SetPicFormat(file.FullName.Replace('\\','/').Replace(Application.dataPath.Replace("Assets", ""), ""));            }        }    }    static void SetPicFormat(string path)    {        TextureImporter importer = AssetImporter.GetAtPath(path) as TextureImporter;        if (importer==null)        {            return;        }        var tempsss = importer.GetPlatformTextureSettings("Android");        bool isNeedFormat = false;        switch (tempsss.format)        {            case TextureImporterFormat.ASTC_RGB_4x4:            case TextureImporterFormat.ASTC_RGB_5x5:            case TextureImporterFormat.ASTC_RGB_6x6:            case TextureImporterFormat.ASTC_RGB_8x8:            case TextureImporterFormat.ASTC_RGB_10x10:            case TextureImporterFormat.ASTC_RGB_12x12:            case TextureImporterFormat.ASTC_RGBA_4x4:            case TextureImporterFormat.ASTC_RGBA_5x5:            case TextureImporterFormat.ASTC_RGBA_6x6:            case TextureImporterFormat.ASTC_RGBA_8x8:            case TextureImporterFormat.ASTC_RGBA_10x10:            case TextureImporterFormat.ASTC_RGBA_12x12:                Debug.Log(path);                isNeedFormat = true;                break;            default:                break;        }        if (!isNeedFormat || !tempsss.overridden)        {            Debug.Log("设置图片格式"+path);            tempsss.overridden = true;            tempsss.format = TextureImporterFormat.ASTC_RGBA_6x6;            tempsss.maxTextureSize = 1024;            importer.SetPlatformTextureSettings(tempsss);            importer.SaveAndReimport();        }    }}
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-9-23 01:20 , Processed in 0.089136 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表