具体可以参照 Unity3d 官方文档。
http://docs.unity3d.com/ScriptReference/AssetPostprocessor.OnPreprocessTexture.html
代码出处:http://blog.csdn.net/huutu
在此基础上添加了设置Filter Mode为Point模式,可以适用于像素图片的处理
当然同样可以处理,如下图所示的所有设置
/**************************
* 文件名:AutoSetTextureUISprite.cs;
* 文件描述:导入图片资源到Unity时,自动修改为UI 2D Sprite,自动设置打包tag 为文件夹名字;
* 创建日期:2015/05/04;
* Author:陈鹏;
***************************/
using UnityEngine;
using System.Collections;
using UnityEditor;
public class AutoSetTextureUISprite :AssetPostprocessor
{
void OnPreprocessTexture()
{
//自动设置类型;
TextureImporter textureImporter = (TextureImporter)assetImporter;
textureImporter.textureType=TextureImporterType.Sprite;
//自动设置打包tag;
string dirName = System.IO.Path.GetDirectoryName(assetPath);
Debug.Log("Import --- "+dirName);
string folderStr = System.IO.Path.GetFileName(dirName);
Debug.Log("Set Packing Tag --- "+folderStr);
textureImporter.spritePackingTag = folderStr;
//filtermode 自动设置为 point
textureImporter.filterMode = FilterMode.Point;//在这里添加就可以了
}
}
把这个.cs文件放入任意一个文件夹都是可以执行的
参考资料3的文章里面还描述了图片批处理,或者是UNITY添加快捷键的设置
文件分流:
Unity图片导入批处理
参考资料: