Unity3D 批量图片资源导入设置

using UnityEngine;
 
using System.Collections;
 
using UnityEditor;
 
/// <summary>
 
/// 批量图片资源导入设置
 
/// 使用说明: 选择需要批量设置的贴图,
 
/// 单击DuanMenu/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[] { “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 void Init()
 
{
 
TextureImportSetting window = (TextureImportSetting)EditorWindow.GetWindow(typeof(TextureImportSetting), true, “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.AutomaticTruecolor;
 
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);
 
}
 
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Current release version: 3.00 (Feb 2 2015) Source tarball jhead-3.00.tar.gz (69 k) Pre-built Windows executable jhead.exe (166 k) Pre-built Linux executable (built on Centos) jhead (77 k) Pre-built OS-X Intel executable (version 2.97) jhead (24 k) ----------------- 简介 一个现成更改照片时间的程式--jhead,由网页中,releases表里下载110k的十分好用。 下载jhead时,记得把jhead程序存放在要更改的照片文件夹里,不然无法使用。 它的强大在于它 一、提供了其他工具所不能企及的功能 二、强大的批处理能力 唯一的问题是:jhead不是个window程式,它是个DOS程式,许多用window的人,对DOS并不熟,因此,说明jhead使用法如下: jhead这个DOS程式必需在DOS下执行,如何在windows中启动DOS? 以windowsXP为例: 开始——运行 在开启处键入cmd C:\DocumentsandSettings\user。这即是我们的电脑硬碟(简化来说。其实只是硬碟的一部份)。试着click这一行最右边,并键入dir。 dir是DOS的command,意思是--显示目录,此时就会看到一串有的字,其中有个桌面,试着键入---cd桌面。 这时出现\DocumentsandSettings\user\桌面,表示已进入桌面这个目录,cd是change directory(改变目录)的意思,试着键入---cd要更改的照片文件夹名称。 这时出现\DocumentsandSettings\user\桌面\你要更改的照片文件夹名称。表示已进入你想更改的目录。接着键入jhead参数 据说该工具最早是在linux环境下开发的,现已被移植到多个平台,包括windows。 但,目前为止并没有GUI,也就是图形外壳,所以理解并使用该工具前你必须了解一些简单的命令行知识 跟所有的命令行工具一样,它的使用方法为:jhead参数列表jpg文件列表 比如: jhead-se1jpg处理单个文件 jhead-se2009_[0-9]jpg处理指定的多个文件 jhead-se*jpg处理所有文件 另外,你甚至可以用**通配符来代替子目录,从而实现对指定目录的遍历!包括子目录的子目录。如: jhead-sec:\tmp\**\*jpg 当然有些参数也允许你联合使用。比如: jhead-se-q1jpg2jpg3jpg 我们举几个例子(jhead如何使用)(命令和参数、文件夹、文件之间必须空格): (一)jhead-da2009:01:01-2008:01:01*jpg 把当前目录下的所有拍摄日期为2008/01/01的照片更改时间为2009/01/01。这在相机日期设置有误时非常有用。(更改照片拍摄日期) (二)jhead-ds2009*jpg 把当前目录下的所有jpg文件的日期年份更改为2009年,保持日期的其他部分(月、日及时间)不变! (三)jhead-nf%Y_%m%d_i*jpg 把当前目录下的所有jpg文件的文件名更改为:年4位_月2位日2位_4位序号jpg如:2009_1201_0001jpg (四)jhead-seld_picjpg>atxt 有时候你可能需要把照片的exif信息转入文体保存,你可以直接重定向输出就可以了 (五)jhead-st"bak\&i"*jpg 把当前目录下的所有文件的缩略图复制保存到bak目录下并与原文件名同名。 (六)jhead-te01jpg02jpg 单个文件导入,把01jpg的信息导入到02jpg,覆盖原来的。 jhead-te"bak\&i"*jpg 批量导入,把bak目录下的jpg文件信息按文件名一一对应的导入当前目录下的jpg文件!引号不省略!! 实例一下吧 jhead命令(参数)大全 -V(大写的V)显示jhead的版本 -h获得帮助 -autorot根据exif中记录的水平方向信息转动照片 -norot清除exif中记录的水平方向信息 -v(小写的v)详细的exif信息显示 -exifmap显示头信息,总之跟v不一样 -se简化显示 -c精简显示(比-se更简单) -dc删除jpg信息中的备注 -de完全删除exif信息 -du删除非原始exif信息,例如Photoshop之类编辑后修改exif留下的信息 -purejpg删除所有jpg文件非必须信息相当于-de-dc-du的集合,文件将减小数k -mkexif创建新的最小exif信息(覆盖原有的的exif信息),不明白这有什么用 -di删除IPTC(Photoshop格式兼容)信息 -dx删除XMP(photoshop文件信息) -te从其他jpg文件导入exif信息到当前文件 -dc删除jpg信息中的备注 -ce使用系统默认编辑器编辑备注。运行时会自动打开文本编辑器,录完信息,保存并关闭后,信息会自动被写入备注 -cs导出备注到文本文件。如:jhead-cs1txt1jpg -ci从文体文件导入备注。如:jhead-ci1txt1jpg -clstring直接输入备注。如:jhead–cl我爱无常版主1jpg -dt删除exif中的缩略图此缩略图一般240x160象素,10k大小 -st[name]将exif中的缩略图复制为另一个jpg文件 -rt[name]用另一个jpg文件替换exif中的缩略图 -rgt[size]刷新exif缩略图,其中[size]为缩略图的最大边长 -ft将jpg文件的“修改时间”修改为exif信息中记录的拍摄时间 -dsft把照片exif信息时间设置为文件修改时间 -da[date1]-[date2]把拍摄日期为data2的照片日期修正为data1;date格式为yyyy:mm:dd或yyyy:mm:dd+hh:mm或yyyy:mm:dd+hh:mm:ss -ts[time]直接修改exif中的时间,格式为yyyy:mm:dd-hh:mm:ss -ds[date]直接修改exif中的日期,格式为yyyy:mm:dd或yyyy:mm或yyyy -ta[+|-]h[:mm[:ss]]修正时差,根据时区确定,例如+1:00或者-1:00 -n[format-string]将照片文件名修改为exif信息中记录的“数字化时间”,保留原文件名;如果exif数字化时间不可用,则将文件名修改为文件的“修改时间” -nf[format-string]与"-n"相同功能相同,不保留原文件名 format-string格式说明 %d日(01-31) %H小时(00-23) %j一年中的第几天(001-366) %m月(01-12) %M分钟(00-59) %S秒(00-59) %U一年中的第几周(00-53) %w星期几(0-6,周日为0) %y两位数纪年(00-99) %Y四位数纪年 %i添加数字序号,也可以指定位数。如:i(生成4位序号,不足的高位补零) %f原文件名 -q不显示程序运行信息,和其他参数一起使用。这在编写批处理脚本时非常有用 -cmdcommand调用其他程序,如:jhead-cmd"mogrify-qlity80&i"*jpg -exonly不处理没有exif信息的文件,要和其他参数一起使用 -a修改不同扩展名的同名文件名。拍摄的avi短片exif信息存储在同名thm文件中,可用此指令给avi文件更名一般与-n共同使用

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值