批量修改贴图导入设置工具脚本
2017-09-30 10:56
459 查看
这个Unity3D批量修改贴图导入设置工具脚本十分小巧,但是威力大。特别针对大批量贴图要调整尺寸等等的时候作用尤为明显。在菜单中添加“Custom→Texture”的方式来批量改变所选的贴图导入设置。Unity本身只能一次打开一张图片进行导入设置,目前这个脚本可以批量更改贴图格式,是否开启MipMap,调整纹理最大尺寸,是否可读等等。
用法是把脚本放在你项目的资源目录的Editor文件夹下。然后选择你要批处理的纹理。到菜单中选择要处理的类型就可以了。
ChangeTextureImportSettings。csforUnity2.x
程序代码csharp代码:
用法是把脚本放在你项目的资源目录的Editor文件夹下。然后选择你要批处理的纹理。到菜单中选择要处理的类型就可以了。
ChangeTextureImportSettings。csforUnity2.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: ms@decane.net // // ///////////////////////////////////////////////////////////////////////////////////////////////////////// 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() { S 4000 electedChangeTextureFormatSettings(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); } //Unity3D教程手册:www.unitymanual.com [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); } // ---------------------------------------------------------------------------- // 查看本栏目更多精彩内容:http://www.bianceng.cn/Programming/extra/ [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); } } //Unity3D教程手册:www.unitymanual.com 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); } }
相关文章推荐
- Unity3d 批量修改贴图导入设置工具脚本
- 【Unity小工具】批量修改原始资源设置
- 批处理制作DataStage脚本批量import和compile导入小工具
- 使用JScript脚本批量修改VC工程设置
- 使用JScript脚本批量修改VC工程设置
- 批量将导入的图片生成对应的元件调整为无损位图质量,设置链接项导出,发布并生成配置文件,fljs小命令脚本 - [jsfl]
- 文件名批量修改工具V1.0 绿色版
- ORACLE 快速批量导入文本数据到数据库(sqlldr工具)方法与分析
- 实现Windows non-Unicode设置批量修改 推荐
- 使用Js脚本 修改控制IE的注册表相关设置(activex等)
- pyhon 脚本实现批量日志信息导入外部表分区
- 批量修改AD用户属性python脚本
- linux shell脚本批量修改密码,无需交互输入
- 小工具批量修改名字
- A Better Finder Attributes for Mac (文件图片批量修改工具)免注册码 v6.05中文破解版
- 批量修改root密码#shell脚本
- Unity3D 批量图片资源导入设置
- PuTTY使用笔记:登录设置的批量备份导出/导入
- 修改贴图工具
- AD用户设置系列】批量修改漫游配置文件路径