背景
Unity中导入图片图片大都需要使用手动改为spirit模式,尤其是制作二维游戏时,所以制作一个小工具,将导入Unity的所有图片模式都改变为sprite模式
编写过程
1、新建文件夹Editor
2、创建脚本TextureSettings
using UnityEditor;
//继承导入过程类
public class TextureSettings :AssetPostprocessor
{
private void OnPreprocessTexture()
{
//获取导入的对象
TextureImporter importer = (TextureImporter)assetImporter;
//改变图片的类型
importer.textureType = TextureImporterType.Sprite;
}
}
虽然功能很小,但是不用手动去改变了,很耐斯!!!!!!
升级版
只改变导入到sprites文件夹下的图片,判断文件路径就行了:
using UnityEditor;
using UnityEngine;
public class SpriteProcessor : AssetPostprocessor
{
private void OnPostprocessTexture(Texture2D texture)
{
if (assetPath.ToLower().IndexOf("/sprites/") != -1)
{
TextureImporter textureImporter = (TextureImporter)assetImporter;
textureImporter.textureType = TextureImporterType.Sprite;
textureImporter.spriteImportMode = SpriteImportMode.Single;
textureImporter.alphaIsTransparency = true;
textureImporter.mipmapEnabled = false;
}
}
}