查看: 3649|回复: 8
打印 上一主题 下一主题

[其他] unity3d 批量更改图片属性插件 TextureImportSetting

[复制链接]

1023

主题

3

听众

359

积分

设计实习生

Rank: 2

纳金币
335582
精华
0

最佳新人

跳转到指定楼层
楼主
发表于 2011-10-8 07:55:00 |只看该作者 |倒序浏览

          using UnityEngine;
         
            
         

           using System.Collections;
           



           using UnityEditor;
         

           /// <summary>
           



           /// 批量图片资源导入设置
           



           /// 使用说明: 在Assets文件夹下创建Editor文件夹,将复制或拷贝该代码--
           



           /// 保存成TextureImportSetting.cs放入Editor文件夹,将该脚本放入该文件--
           



           /// 夹选择需要批量设置的贴图,单击Costom/Texture Import Settings,打--
           



           /// 开窗口后选择对应参数,点击Set Texture ImportSettings,稍等片刻,--
           



           /// 批量设置成功。
           



           /// </summary>
           



           public class TextureImportSetting : 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[] { "oint", "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", "***e color" };
         

               /// <summary>
           



               /// 创建、显示窗体
           



               /// </summary>
           



               [@MenuItem("Custom/Texture Import Settings")]
           



               private static void Init()
           



               {
           



                   TextureImportSetting window = (TextureImportSetting)GetWindow(typeof(TextureImportSetting), ***e, "TextureImportSetting");
           



                   window.Show();
           



               }
         

               /// <summary>
           



               /// 显示窗体里面的内容
           



               /// </summary>
           



               private void OnGUI()
           



               {
           



                   //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(string path)
           



               {
           



                   TextureImporter textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;
         

                   //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.Automatic***ecolor;
           



                           break;
           



                   }
         

                   return textureImporter;
           



               }
         

               /// <summary>
           



               /// 循环设置选择的贴图
           



               /// </summary>
           



               private void LoopSetTexture()
           



               {
           



                   Object[] textures = GetSelectedTextures();
           



                   Selection.objects = new Object[0];
         

                   foreach (Texture2D texture in textures)
           



                   {
           



                       string path = AssetDatabase.GetAssetPath(texture);
           



                       TextureImporter texImporter = GetTextureSettings(path);
           



                       TextureImporterSettings tis = new TextureImporterSettings();
           



                       texImporter.ReadTextureSettings(tis);
           



                       texImporter.SetTextureSettings(tis);
           



                       AssetDatabase.ImportAsset(path);
           



                   }
           



               }
         

               /// <summary>
           



               /// 获取选择的贴图
           



               /// </summary>
           



               /// <returns></returns>
           



               private Object[] GetSelectedTextures()
           



               {
           



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



               }
           



           }
         
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

tc    

5089

主题

1

听众

33万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

沙发
发表于 2012-1-20 23:24:25 |只看该作者
年末感慨实在是多,三言两语道不完!最让我揪心的还是你,行李备好了没?火车票买了没?别感动,我只是问问,自己的事情还是要自己做滴!哈哈。
回复

使用道具 举报

tc    

5089

主题

1

听众

33万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

板凳
发表于 2012-3-3 23:26:43 |只看该作者
楼主收集的可真全哦
回复

使用道具 举报

1023

主题

3

听众

359

积分

设计实习生

Rank: 2

纳金币
335582
精华
0

最佳新人

地板
发表于 2012-4-25 23:20:52 |只看该作者
好铁多多发,感激分享
回复

使用道具 举报

1023

主题

3

听众

359

积分

设计实习生

Rank: 2

纳金币
335582
精华
0

最佳新人

5#
发表于 2012-5-7 23:22:34 |只看该作者
先顶上去,偶要高亮加精鸟!
回复

使用道具 举报

462

主题

1

听众

31万

积分

首席设计师

Rank: 8Rank: 8

纳金币
2
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

6#
发表于 2012-8-28 23:39:12 |只看该作者
很有心,部分已收录自用,谢谢
回复

使用道具 举报

5969

主题

1

听众

39万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

7#
发表于 2012-10-25 23:49:50 |只看该作者
先顶上去,偶要高亮加精鸟!
回复

使用道具 举报

1023

主题

3

听众

359

积分

设计实习生

Rank: 2

纳金币
335582
精华
0

最佳新人

8#
发表于 2013-2-10 23:18:50 |只看该作者
我是老实人,我来也!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

关闭

站长推荐上一条 /1 下一条

手机版|纳金网 ( 闽ICP备08008928号

GMT+8, 2024-5-14 05:50 , Processed in 0.096105 second(s), 28 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部