Unity3D 批量图片资源导入设置

摘要:
原地址:http://blog.csdn.net/asd237241291/article/details/8433548创文章如需转载请注明:转载自脱莫柔Unity3D学习之旅QQ群:【119706192】本文链接地址:Unity3D批量图片资源导入设置复制代码usingUnityEngine;usingSystem.Collections;usingUnityEditor;///˂summar

原地址:http://blog.csdn.net/asd237241291/article/details/8433548

创文章如需转载请注明:转载自 脱莫柔Unity3D学习之旅  QQ群:【119706192】 本文链接地址: Unity3D 批量图片资源导入设置
复制代码
usingUnityEngine;
usingSystem.Collections;
usingUnityEditor;
/// <summary>
///批量图片资源导入设置
///使用说明: 选择需要批量设置的贴图,
///单击DuanMenu/Texture Import Settings,
///打开窗口后选择对应参数,
///点击Set Texture ImportSettings,
///稍等片刻,--批量设置成功。
/// </summary>
public classTextureImportSetting : EditorWindow {
    /// <summary>
    ///临时存储int[]
    /// </summary>
    private int[] IntArray = new int[] { 0, 1, 2, 3, 4, 5, 6, 7};
    //AnisoLevel
    private int AnisoLevel = 1;
    //Filter Mode
    private int FilterModeInt = 0;
    private string[] FilterModeString = new string[] { "Point", "Bilinear", "Trilinear"};
    //Wrap Mode
    private int WrapModeInt = 0;
    private string[] WrapModeString = new string[] { "Repeat", "Clamp"};
    //Texture Type
    private int TextureTypeInt = 0;
    private string[] TextureTypeString = new string[] { "Texture", "Normal Map", "GUI", "Refelection", "Cookie", "Lightmap", "Advanced"};
    //Max Size
    private int MaxSizeInt = 5;
    private string[] MaxSizeString = new string[] { "32", "64", "128", "256", "512", "1024", "2048", "4096"};
    //Format
    private int FormatInt = 0;
    private string[] FormatString = new string[] { "Compressed", "16 bits", "true color"};
    /// <summary>
    ///创建、显示窗体
    /// </summary>
    [@MenuItem("DuanMenu/Texture Import Settings")]
    private static voidInit()
    {    
        TextureImportSetting window = (TextureImportSetting)EditorWindow.GetWindow(typeof(TextureImportSetting), true, "TextureImportSetting");
        window.Show();
    }
    /// <summary>
    ///显示窗体里面的内容
    /// </summary>
    private voidOnGUI()
    {
        //AnisoLevel
GUILayout.BeginHorizontal();
        GUILayout.Label("Aniso Level  ");
        AnisoLevel = EditorGUILayout.IntSlider(AnisoLevel, 0, 9);
        GUILayout.EndHorizontal();
        //Filter Mode
        FilterModeInt = EditorGUILayout.IntPopup("Filter Mode", FilterModeInt, FilterModeString, IntArray);
        //Wrap Mode
        WrapModeInt = EditorGUILayout.IntPopup("Wrap Mode", WrapModeInt, WrapModeString, IntArray);
        //Texture Type
        TextureTypeInt = EditorGUILayout.IntPopup("Texture Type", TextureTypeInt, TextureTypeString, IntArray);
        //Max Size
        MaxSizeInt = EditorGUILayout.IntPopup("Max Size", MaxSizeInt, MaxSizeString, IntArray);
        //Format
        FormatInt = EditorGUILayout.IntPopup("Format", FormatInt, FormatString, IntArray);
        if (GUILayout.Button("Set Texture ImportSettings"))
            LoopSetTexture();
    }
    /// <summary>
    ///获取贴图设置
    /// </summary>
    public TextureImporter GetTextureSettings(stringpath)
    {
        TextureImporter textureImporter = AssetImporter.GetAtPath(path) asTextureImporter;
        //AnisoLevel
        textureImporter.anisoLevel =AnisoLevel;
        //Filter Mode
        switch(FilterModeInt)
        {
            case 0:
                textureImporter.filterMode =FilterMode.Point;
                break;
            case 1:
                textureImporter.filterMode =FilterMode.Bilinear;
                break;
            case 2:
                textureImporter.filterMode =FilterMode.Trilinear;
                break;
        }
        //Wrap Mode
        switch(WrapModeInt)
        {
            case 0:
                textureImporter.wrapMode =TextureWrapMode.Repeat;
                break;
            case 1:
                textureImporter.wrapMode =TextureWrapMode.Clamp;
                break;
        }
        //Texture Type
        switch(TextureTypeInt)
        {
            case 0:
                textureImporter.textureType =TextureImporterType.Image;
                break;
            case 1:
                textureImporter.textureType =TextureImporterType.Bump;
                break;
            case 2:
                textureImporter.textureType =TextureImporterType.GUI;
                break;
            case 3:
                textureImporter.textureType =TextureImporterType.Reflection;
                break;
            case 4:
                textureImporter.textureType =TextureImporterType.Cookie;
                break;
            case 5:
                textureImporter.textureType =TextureImporterType.Lightmap;
                break;
            case 6:
                textureImporter.textureType =TextureImporterType.Advanced;
                break;
        }
        //Max Size 
        switch(MaxSizeInt)
        {
            case 0:
                textureImporter.maxTextureSize = 32;
                break;
            case 1:
                textureImporter.maxTextureSize = 64;
                break;
            case 2:
                textureImporter.maxTextureSize = 128;
                break;
            case 3:
                textureImporter.maxTextureSize = 256;
                break;
            case 4:
                textureImporter.maxTextureSize = 512;
                break;
            case 5:
                textureImporter.maxTextureSize = 1024;
                break;
            case 6:
                textureImporter.maxTextureSize = 2048;
                break;
            case 7:
                textureImporter.maxTextureSize = 4096;
                break;
        }
        //Format
        switch(FormatInt)
        {
            case 0:
                textureImporter.textureFormat =TextureImporterFormat.AutomaticCompressed;
                break;
            case 1:
                textureImporter.textureFormat =TextureImporterFormat.Automatic16bit;
                break;
            case 2:
                textureImporter.textureFormat =TextureImporterFormat.AutomaticTruecolor;
                break;
        }
        returntextureImporter;
    }
    /// <summary>
    ///循环设置选择的贴图
    /// </summary>
    private voidLoopSetTexture()
    {
        Object[] textures =GetSelectedTextures();
        Selection.objects = new Object[0];
        foreach (Texture2D texture intextures)
        {
            string path =AssetDatabase.GetAssetPath(texture);
            TextureImporter texImporter =GetTextureSettings(path);
            TextureImporterSettings tis = newTextureImporterSettings();
            texImporter.ReadTextureSettings(tis);
            texImporter.SetTextureSettings(tis);
            AssetDatabase.ImportAsset(path);
        }
    }
    /// <summary>
    ///获取选择的贴图
    /// </summary>
    /// <returns></returns>
    privateObject[] GetSelectedTextures()
    {
        return Selection.GetFiltered(typeof(Texture2D), SelectionMode.DeepAssets);
    }
}
复制代码

免责声明:文章转载自《Unity3D 批量图片资源导入设置》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Ansible安装配置及使用机器人学——2.3-姿态插值和笛卡尔运动下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Unity iOS打开AppStore评星页面,浅谈Application.OpenURL()方法。

http://fairwoodgame.com/blog/?p=38 Unity iOS打开AppStore评星页面,浅谈Application.OpenURL()方法。 Posted in UnityonAugust 6, 2013Comments:暂无评论 太简单了。我们知道iOS里有个URL Scheme的东西(这个我还没深究,希望有大神帮我贴...

fastJSON 使用总结

1.介绍Fastjson Fastjson是一个Java语言编写的JSON处理器。 如果获得Fastjson?https://github.com/alibaba/fastjson 2.使用Fastjson Json互转List<T> 比如说List<Strudent> List转Json List<Student>...

asp.net mvc+EF 递归生成树结构返回json

0、数据表结构,主要属性有:Id、parentId(父节Id)、Text、Url……等等。 1、新建一个树结构MenuModels 1 public class MenuModels 2 { 3 private int _id; 4 private string _text; 5...

C#第三方Aspose.Words.dll导出Word(书签模板)方式说明

项目有遇到需要导出Word,在别人写好的基础上去修改样式,导出后发现样式不正确不整齐,于是采用模板的方式重新导出 1.模板word文件的制作,本人用office2013,在设计好需要的整个表格之后,在你需要替换的位置"插入"--书签 并命名,此命名需要在程序中进行替换 将做好的模板word文件放在程序目录下 2.引用Aspose.Words.dll 3.新...

对json进行封装

项目中经常用到对于JSON的各种转换处理,保存一份,免得以后忘了。 using System; using System.Collections.Generic; using System.Text; using System.Reflection; using System.Data; using System.Collections; using CR...

iOS--Block的那些事

假设我们熟悉代理递值的话,对代理我们可能又爱有恨!我们先建立模型A页面 push B页面,如果把A页面的值传递到B页面,属性和单例传值可以搞定!但是如果Pop过程中把B页面的值传递到A页面,那就可以用单例或者代理了!说到代理,我们要先声明协议,创建代理,很是麻烦。常常我们传递一个数值需要在两个页面间写很多代码,这些代码改变页面的整体顺序,可读性也打了折扣。...