Unity3D 批量修改贴图导入设置工具脚本

这个Unity3D
批量修改贴图导入设置工具脚本十分小巧,但是威力大.特别针对大批量贴图要调整尺寸等等的时候作用尤为明显。在菜单中添加"Custom→Texture"的方式来批量改变所选的贴图导入设置.Unity本身只能一次打开一张图片进行导入设置,目前这个脚本可以批量更改贴图格式,是否开启MipMap,调整纹理最大尺寸,是否可读等等.

用法是把脚本放在你项目的资源目录的Editor文件夹下.然后选择你要批处理的纹理.到菜单中选择要处理的类型就可以了.

ChangeTextureImportSettings.cs
for Unity2.x

程序代码 csharp 代码

using UnityEngine;
using
UnityEditor;

//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//
Batch Texture import settings modifier.
//
// Modifies all selected
textures in the project window and applies the requested modification on
the 
// textures. Idea was to have the same choices for multiple files
as you would have if you open the 
// import settings of a single
texture. Put this into Assets/Editor and once compiled by Unity you find
//
the new functionality in Custom -> Texture. Enjoy! :-)
// 
//
Based on the great work of benblo in this thread: 
//
http://forum.unity3d.com/viewtopic.php?t=16079&start=0&postdays=0&postorder=asc&highlight=textureimporter
// 
//
Developed by Martin Schultz, Decane in August 2009
// e-mail:
[email protected]
//
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
public
class ChangeTextureImportSettings : ScriptableObject
{
    
    [MenuItem
("Custom/Texture/Change Texture Format/Auto")]
    static void
ChangeTextureFormat_Auto() { 
       
SelectedChangeTextureFormatSettings(TextureImporterFormat.Automatic);
   
}
        
   
[MenuItem ("Custom/Texture/Change Texture Format/RGB Compressed
DXT1")]
    static void ChangeTextureFormat_RGB_DXT1()

       
SelectedChangeTextureFormatSettings(TextureImporterFormat.DXT1);
   
}
    
    [MenuItem
("Custom/Texture/Change Texture Format/RGB Compressed
DXT5")]
    static void ChangeTextureFormat_RGB_DXT5()

       
SelectedChangeTextureFormatSettings(TextureImporterFormat.DXT5);
   
}
    
    [MenuItem
("Custom/Texture/Change Texture Format/RGB 16 bit")]
   
static void ChangeTextureFormat_RGB_16bit()

       
SelectedChangeTextureFormatSettings(TextureImporterFormat.RGB16);
   
}
    
    [MenuItem
("Custom/Texture/Change Texture Format/RGB 24 bit")]
   
static void ChangeTextureFormat_RGB_24bit()

       
SelectedChangeTextureFormatSettings(TextureImporterFormat.RGB24);
   
}
    
    [MenuItem
("Custom/Texture/Change Texture Format/Alpha 8 bit")]
   
static void ChangeTextureFormat_Alpha_8bit()

       
SelectedChangeTextureFormatSettings(TextureImporterFormat.Alpha8);
   
}
    
    [MenuItem
("Custom/Texture/Change Texture Format/RGBA 16 bit")]
   
static void ChangeTextureFormat_RGBA_16bit()

       
SelectedChangeTextureFormatSettings(TextureImporterFormat.ARGB16);
   
}
    
    [MenuItem
("Custom/Texture/Change Texture Format/RGBA 32 bit")]
   
static void ChangeTextureFormat_RGBA_32bit()

       
SelectedChangeTextureFormatSettings(TextureImporterFormat.ARGB32);
   
}
    
    //
----------------------------------------------------------------------------
    
   
[MenuItem ("Custom/Texture/Change Texture Size/Change Max Texture
Size/32")]
    static void ChangeTextureSize_32()

       
SelectedChangeMaxTextureSize(32);
   
}
    
    [MenuItem
("Custom/Texture/Change Texture Size/Change Max Texture
Size/64")]
    static void ChangeTextureSize_64()

       
SelectedChangeMaxTextureSize(64);
   
}
    
    [MenuItem
("Custom/Texture/Change Texture Size/Change Max Texture
Size/128")]
    static void ChangeTextureSize_128()

       
SelectedChangeMaxTextureSize(128);
   
}
    
    [MenuItem
("Custom/Texture/Change Texture Size/Change Max Texture
Size/256")]
    static void ChangeTextureSize_256()

       
SelectedChangeMaxTextureSize(256);
   
}
    
    [MenuItem
("Custom/Texture/Change Texture Size/Change Max Texture
Size/512")]
    static void ChangeTextureSize_512()

       
SelectedChangeMaxTextureSize(512);
   
}
    
    [MenuItem
("Custom/Texture/Change Texture Size/Change Max Texture
Size/1024")]
    static void ChangeTextureSize_1024()

       
SelectedChangeMaxTextureSize(1024);
   
}
    
    [MenuItem
("Custom/Texture/Change Texture Size/Change Max Texture
Size/2048")]
    static void ChangeTextureSize_2048()

       
SelectedChangeMaxTextureSize(2048);
   
}
    
    //
----------------------------------------------------------------------------
    
   
[MenuItem ("Custom/Texture/Change MipMap/Enable MipMap")]
   
static void ChangeMipMap_On()

       
SelectedChangeMimMap(true);
   
}
    
    [MenuItem
("Custom/Texture/Change MipMap/Disable MipMap")]
    static
void ChangeMipMap_Off() { 
       
SelectedChangeMimMap(false);
   
}
    
    //
----------------------------------------------------------------------------
    
   
static void SelectedChangeMimMap(bool enabled)

    
       
Object[] textures =
GetSelectedTextures(); 
       
Selection.objects = new Object[0];
       
foreach (Texture2D texture in textures) 
{
            string
path =
AssetDatabase.GetAssetPath(texture); 
           
TextureImporter textureImporter = AssetImporter.GetAtPath(path) as
TextureImporter; 
           
textureImporter.mipmapEnabled =
enabled;    
           
AssetDatabase.ImportAsset(path); 
       
}
    }
    
   
static void SelectedChangeMaxTextureSize(int size)

    
       
Object[] textures =
GetSelectedTextures(); 
       
Selection.objects = new Object[0];
       
foreach (Texture2D texture in textures) 
{
            string
path =
AssetDatabase.GetAssetPath(texture); 
           
TextureImporter textureImporter = AssetImporter.GetAtPath(path) as
TextureImporter; 
           
textureImporter.maxTextureSize =
size;  
           
AssetDatabase.ImportAsset(path); 
       
}
    }
    
   
static void SelectedChangeTextureFormatSettings(TextureImporterFormat newFormat)

    
       
Object[] textures =
GetSelectedTextures(); 
       
Selection.objects = new Object[0];
       
foreach (Texture2D texture in textures) 
{
            string
path =
AssetDatabase.GetAssetPath(texture); 
           
//Debug.Log("path: " +
path);
           
TextureImporter textureImporter = AssetImporter.GetAtPath(path) as
TextureImporter; 
           
textureImporter.textureFormat =
newFormat;  
           
AssetDatabase.ImportAsset(path); 
       
}
    }
    
   
static Object[] GetSelectedTextures() 
   

        return
Selection.GetFiltered(typeof(Texture2D),
SelectionMode.DeepAssets); 
   
}
}

ChangeTextureImportSettingsUnity3 for Unity3.x

程序代码 csharp 代码

using UnityEngine;
using UnityEditor;

//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//
Batch Texture import settings modifier.
//
// Modifies all selected
textures in the project window and applies the requested modification on
the 
// textures. Idea was to have the same choices for multiple files
as you would have if you open the 
// import settings of a single
texture. Put this into Assets/Editor and once compiled by Unity you find
//
the new functionality in Custom -> Texture. Enjoy! :-)
// 
//
Based on the great work of benblo in this thread: 
//
http://forum.unity3d.com/viewtopic.php?t=16079&start=0&postdays=0&postorder=asc&highlight=textureimporter
// 
//
Developed by Martin Schultz, Decane in August 2009
// e-mail:
[email protected]
//
// Updated for Unity 3.0 by col000r in August 2010
//
http://col000r.blogspot.com
//
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
public
class ChangeTextureImportSettingsUnity3 : ScriptableObject
{
    
    [MenuItem
("Custom/Texture/Change Texture Format/Auto Compressed")]
   
static void ChangeTextureFormat_AutoCompressed()

       
SelectedChangeTextureFormatSettings(TextureImporterFormat.AutomaticCompressed);
   
}

    [MenuItem ("Custom/Texture/Change Texture
Format/Auto 16bit")]
    static void
ChangeTextureFormat_Auto16Bit()

       
SelectedChangeTextureFormatSettings(TextureImporterFormat.Automatic16bit);
   
}

    [MenuItem ("Custom/Texture/Change Texture
Format/Auto Truecolor")]
    static void
ChangeTextureFormat_AutoTruecolor()

       
SelectedChangeTextureFormatSettings(TextureImporterFormat.AutomaticTruecolor);
   
}
        
   
[MenuItem ("Custom/Texture/Change Texture Format/RGB Compressed
DXT1")]
    static void ChangeTextureFormat_RGB_DXT1()

       
SelectedChangeTextureFormatSettings(TextureImporterFormat.DXT1);
   
}
    
    [MenuItem
("Custom/Texture/Change Texture Format/RGB Compressed
DXT5")]
    static void ChangeTextureFormat_RGB_DXT5()

       
SelectedChangeTextureFormatSettings(TextureImporterFormat.DXT5);
   
}
    
    [MenuItem
("Custom/Texture/Change Texture Format/RGB 16 bit")]
   
static void ChangeTextureFormat_RGB_16bit()

       
SelectedChangeTextureFormatSettings(TextureImporterFormat.RGB16);
   
}
    
    [MenuItem
("Custom/Texture/Change Texture Format/RGB 24 bit")]
   
static void ChangeTextureFormat_RGB_24bit()

       
SelectedChangeTextureFormatSettings(TextureImporterFormat.RGB24);
   
}
    
    [MenuItem
("Custom/Texture/Change Texture Format/Alpha 8 bit")]
   
static void ChangeTextureFormat_Alpha_8bit()

       
SelectedChangeTextureFormatSettings(TextureImporterFormat.Alpha8);
   
}
    
    [MenuItem
("Custom/Texture/Change Texture Format/ARGB 16 bit")]
   
static void ChangeTextureFormat_RGBA_16bit()

       
SelectedChangeTextureFormatSettings(TextureImporterFormat.ARGB16);
   
}
    
    [MenuItem
("Custom/Texture/Change Texture Format/RGBA 32 bit")]
   
static void ChangeTextureFormat_RGBA_32bit()

       
SelectedChangeTextureFormatSettings(TextureImporterFormat.RGBA32);
   
}

    [MenuItem ("Custom/Texture/Change Texture
Format/ARGB 32 bit")]
    static void
ChangeTextureFormat_ARGB_32bit()

       
SelectedChangeTextureFormatSettings(TextureImporterFormat.ARGB32);
   
}

    [MenuItem ("Custom/Texture/Change Texture Format/RGB
PVRTC 2bit")]
    static void
ChangeTextureFormat_RGB_PVRTC_2bit()

       
SelectedChangeTextureFormatSettings(TextureImporterFormat.PVRTC_RGB2);
   
}
    
    [MenuItem
("Custom/Texture/Change Texture Format/RGBA PVRTC 2bit")]
   
static void ChangeTextureFormat_RGBA_PVRTC_2bit()

       
SelectedChangeTextureFormatSettings(TextureImporterFormat.PVRTC_RGBA2);
   
}    

    [MenuItem
("Custom/Texture/Change Texture Format/RGB PVRTC 4bit")]
   
static void ChangeTextureFormat_RGB_PVRTC_4bit()

       
SelectedChangeTextureFormatSettings(TextureImporterFormat.PVRTC_RGB4);
   
}
    
    [MenuItem
("Custom/Texture/Change Texture Format/RGBA PVRTC 4bit")]
   
static void ChangeTextureFormat_RGBA_PVRTC_4bit()

       
SelectedChangeTextureFormatSettings(TextureImporterFormat.PVRTC_RGBA4);
   
}
        
    //
----------------------------------------------------------------------------
    
   
[MenuItem ("Custom/Texture/Change Texture Size/Change Max Texture
Size/32")]
    static void ChangeTextureSize_32()

       
SelectedChangeMaxTextureSize(32);
   
}
    
    [MenuItem
("Custom/Texture/Change Texture Size/Change Max Texture
Size/64")]
    static void ChangeTextureSize_64()

       
SelectedChangeMaxTextureSize(64);
   
}
    
    [MenuItem
("Custom/Texture/Change Texture Size/Change Max Texture
Size/128")]
    static void ChangeTextureSize_128()

       
SelectedChangeMaxTextureSize(128);
   
}
    
    [MenuItem
("Custom/Texture/Change Texture Size/Change Max Texture
Size/256")]
    static void ChangeTextureSize_256()

       
SelectedChangeMaxTextureSize(256);
   
}
    
    [MenuItem
("Custom/Texture/Change Texture Size/Change Max Texture
Size/512")]
    static void ChangeTextureSize_512()

       
SelectedChangeMaxTextureSize(512);
   
}
    
    [MenuItem
("Custom/Texture/Change Texture Size/Change Max Texture
Size/1024")]
    static void ChangeTextureSize_1024()

       
SelectedChangeMaxTextureSize(1024);
   
}
    
    [MenuItem
("Custom/Texture/Change Texture Size/Change Max Texture
Size/2048")]
    static void ChangeTextureSize_2048()

       
SelectedChangeMaxTextureSize(2048);
   
}
    
    //
----------------------------------------------------------------------------
    
   
[MenuItem ("Custom/Texture/Change MipMap/Enable MipMap")]
   
static void ChangeMipMap_On()

       
SelectedChangeMimMap(true);
   
}
    
    [MenuItem
("Custom/Texture/Change MipMap/Disable MipMap")]
    static
void ChangeMipMap_Off() { 
       
SelectedChangeMimMap(false);
   
}
    
    //
----------------------------------------------------------------------------

   
[MenuItem ("Custom/Texture/Change Non Power of 2/None")]
   
static void ChangeNPOT_None()

       
SelectedChangeNonPowerOf2(TextureImporterNPOTScale.None);
   
}
 
    [MenuItem ("Custom/Texture/Change Non Power of
2/ToNearest")]
    static void ChangeNPOT_ToNearest()

       
SelectedChangeNonPowerOf2(TextureImporterNPOTScale.ToNearest);
   
}
    
    [MenuItem
("Custom/Texture/Change Non Power of 2/ToLarger")]
    static
void ChangeNPOT_ToLarger() { 
      
SelectedChangeNonPowerOf2(TextureImporterNPOTScale.ToLarger);
   
}

    [MenuItem ("Custom/Texture/Change Non Power of
2/ToSmaller")]
    static void ChangeNPOT_ToSmaller()

       
SelectedChangeNonPowerOf2(TextureImporterNPOTScale.ToSmaller);
   
}    
    
    //
----------------------------------------------------------------------------

   
[MenuItem ("Custom/Texture/Change Is Readable/Enable")]
   
static void ChangeIsReadable_Yes()

       
SelectedChangeIsReadable(true);
   
}
 
    [MenuItem ("Custom/Texture/Change Is
Readable/Disable")]
    static void ChangeIsReadable_No()

       
SelectedChangeIsReadable(false);
   
}    
    
    //
----------------------------------------------------------------------------

   
static void SelectedChangeIsReadable(bool enabled)

    
       
Object[] textures =
GetSelectedTextures(); 
       
Selection.objects = new Object[0];
       
foreach (Texture2D texture in textures) 
{
            string
path =
AssetDatabase.GetAssetPath(texture); 
           
TextureImporter textureImporter = AssetImporter.GetAtPath(path) as
TextureImporter; 
           
textureImporter.isReadable =
enabled;    
           
AssetDatabase.ImportAsset(path); 
       
}
    }

    static void
SelectedChangeNonPowerOf2(TextureImporterNPOTScale npot)

    
       
Object[] textures =
GetSelectedTextures(); 
       
Selection.objects = new Object[0];
       
foreach (Texture2D texture in textures) 
{
            string
path =
AssetDatabase.GetAssetPath(texture); 
           
TextureImporter textureImporter = AssetImporter.GetAtPath(path) as
TextureImporter; 
           
textureImporter.npotScale =
npot;    
           
AssetDatabase.ImportAsset(path); 
       
}
    }
    
   
static void SelectedChangeMimMap(bool enabled)

    
       
Object[] textures =
GetSelectedTextures(); 
       
Selection.objects = new Object[0];
       
foreach (Texture2D texture in textures) 
{
            string
path =
AssetDatabase.GetAssetPath(texture); 
           
TextureImporter textureImporter = AssetImporter.GetAtPath(path) as
TextureImporter; 
           
textureImporter.mipmapEnabled =
enabled;    
           
AssetDatabase.ImportAsset(path); 
       
}
    }
    
   
static void SelectedChangeMaxTextureSize(int size)

    
       
Object[] textures =
GetSelectedTextures(); 
       
Selection.objects = new Object[0];
       
foreach (Texture2D texture in textures) 
{
            string
path =
AssetDatabase.GetAssetPath(texture); 
           
TextureImporter textureImporter = AssetImporter.GetAtPath(path) as
TextureImporter; 
           
textureImporter.maxTextureSize =
size;  
           
AssetDatabase.ImportAsset(path); 
       
}
    }
    
   
static void SelectedChangeTextureFormatSettings(TextureImporterFormat newFormat)

    
       
Object[] textures =
GetSelectedTextures(); 
       
Selection.objects = new Object[0];
       
foreach (Texture2D texture in textures) 
{
            string
path =
AssetDatabase.GetAssetPath(texture); 
           
//Debug.Log("path: " +
path);
           
TextureImporter textureImporter = AssetImporter.GetAtPath(path) as
TextureImporter; 
           
textureImporter.textureFormat =
newFormat;  
           
AssetDatabase.ImportAsset(path); 
       
}
    }
    
   
static Object[] GetSelectedTextures() 
   

        return
Selection.GetFiltered(typeof(Texture2D),
SelectionMode.DeepAssets); 
    }
}

转自 XiaoKe‘s Blog ,原文 http://www.1vr.cn/article.asp?id=548

Unity3D 批量修改贴图导入设置工具脚本,布布扣,bubuko.com

时间: 2025-01-01 06:25:48

Unity3D 批量修改贴图导入设置工具脚本的相关文章

windows下 批量修改文件名

Windows系统下批量修改文件名的详细步骤 听语音 | 浏览:11135 | 更新:2017-08-06 01:36 | 标签:windows 1 2 3 4 5 6 7 分步阅读 Windows系统下批量修改文件名的详细步骤 工具/原料 Dos命令操作 简单批量修改文件名 1 在Windows系统上批量修改文件名是非常简单的.选择所有的文件,按F2,然后输入一下描述性的文本,按enter键之后,所选的文件会以输入的描述性文字加数字排列. END 多步修改文件名 在任意一个盘中新建一个文件夹,

【Unity小工具】批量修改原始资源设置

需求:项目中导入了近200个音效文件,我需要批量修改设置,但是编辑器下无法多选修改设置. 解决办法:重写OnPreprocessAudio方法 using UnityEngine; using System.Collections; using UnityEditor; public class AudioSet : AssetPostprocessor { public void OnPreprocessAudio(){ AudioImporter audioImport=assetImpor

Unity3D Editor模式下批量修改prefab

最经遇到一个需要批量修改已经做好的prefab的问题,查了一些资料最终实现了但是还是不够完美,通过学习也发现unity的编辑器功能还是非常强大的.废话不多说直接上代码: 1 [ExecuteInEditMode] 2 [MenuItem("Tools/RecordPoint Add Flame")] 3 private static void RecordPointAddFlame() 4 { 5 GameObject twoSphere = AssetDatabase.LoadAss

Unity3D 中 Generic 动画导入设置和 Root Motion 之间的关系

2条评论 Unity3D 的 Mecanim 动画系统可以直接复用 3DS MAX 中制作的动画文件中的位移,这个就是通过 applyRootMotion 来达成的,我们只需要在使用 Animator 控制动画播放的同时,设置 Animator 的 applyRootMotion 字段为 True 就 OK 了. 那么怎么来利用这个特性达成我们想要的一些效果呢?这个 applyRootMotion 到底指的是啥呢? ApplyRootMotion,从字面上理解来看,是『应用根节点的运动』,听起来

批量导入是批量修改还是批量新增

1.一般基础数据信息的管理功能包括   新增.修改.删除.查询.导入.导出,比如物料信息维护: 这里说到的导入即相对于新增来说,即批量新增的功能: 2.当我所有的数据信息都完善了的情况下,由于业务的变更,需要给这些基础数据信息新增一个字段信息A:这个时候怎么办? 3.注:在新增.修改.导入模块都增加了字段信息A; 方案1.我做一个批量修改导入的模块,取物料信息的唯一字段标识与要导入的字段A,2列,单独去导入,实现批量修改的功能,用户自己去导入: 方案2.用户提供要导入的信息,包括物料信息的唯一标

MFC批量修改文件名工具

1批量修改文件名描述 1.1功能描述 批量修改同一文件夹下文件名字,可以定义一个新名字,后面接着文件从0开始的序号. 1.2所需技术 CFileDialog,CString方法操作得到所需,rename 2批量修改文件名运行流程 3批量修改文件名详细设计 3.1添加文件按钮响应OnAddFile 按下"添加文件"按钮后,打开一个文件对话框objFileDlg.但是要设置objFileDlg最大文件名缓冲区.然后获得第一个文件的起始位置,依次把全部的文件完整名添加到列表控件中,这里列表控

通过修改数据库,批量修改扫描任务的scan window设置

scan windows:创建扫描任务的时候,指定扫描时间范围的一个参数.对于常规的设置,只会指定开始时间,如果设备故障,或者关机等,导致任务没有执行,当开机后,这些被耽误的任务会立即得到执行,这就有可能导致任务在白天的时间段执行. 如果想要确定指导扫描执行的时间段,可以设置scan window参数. 之前创建的所有任务都没有设置过该参数,如果想要批量修改扫描任务的scan windows设置,是否可行呢?通过批量修改数据库内容可行吗? 创建了一个测试任务来查看scan window对应的表字

08一地形编辑&自制贴图导入--《程序员学Unity3d》

要制作出漂亮实用的地形可不简单啊,目前只知道大概怎么做而已.考虑到效率问题,一般会自己制作贴图导入来使用. PS贴图制作,导入Unity3d

C#代码生成工具:文本模板初体验 使用T4批量修改实体框架(Entity Framework)的类名

转自:http://www.cnblogs.com/huangcong/archive/2011/07/20/1931107.html 在之前的文本模板(T4)初体验中我们已经知道了T4的用处,下面就看看如何用它来实现批量修改实体框架(Entity Framework)中的类名.我们都知道ADO.NET 实体数据模型中有一种方式是以数据库模型来生成数据模型的,这是个很简便的实体数据模型生成的方式,但是因为微软提供的自定义接口不足,我们无法实现对生成的数据模型实体类批量进行修改(至少我上网找了很久