在导入大批量图片的时候,每次要改图片属性,这个很麻烦,通过TextureImporter类能方便的修改各种属性。
真是爽,在网上找了一大堆,修改后都没有保存,导致无法拖动到Sprite里。
我贴上我自己的完整的代码吧。
我默认是ps文件夹,你可以按照文件类型或者别的什么。
这样直接拖动到Unity里就直接变了。很方便。
把下面的脚本放入Editor文件夹,没有的话手动建立一个。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
public class SpriteProcessor : AssetPostprocessor
{
//拖入unity的图片自动修改图片的属性为Sprite
private void OnPostprocessTexture(Texture2D texture)
{
if (assetPath.ToLower().IndexOf("/ps/") != -1)
{
TextureImporter textureImporter = (TextureImporter)assetImporter;
if (textureImporter.textureType != TextureImporterType.Sprite)
{
textureImporter.textureType = TextureImporterType.Sprite;
textureImporter.spriteImportMode = SpriteImportMode.Single;
textureImporter.alphaIsTransparency = true;
textureImporter.mipmapEnabled = false;
textureImporter.SaveAndReimport();
//Debug.Log("Texture Insert :"+ assetPath);
}
}
}
}