【Unity】资源导入前的操作
2019-01-12 本文已影响10人
木心Sepith
可以通过继承AssetPostprocessor来进行
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
public class UISpriteImporter : AssetPostprocessor
{
//导入图片资源
void OnPreprocessTexture()
{
//判断目录
if (!assetPath.Contains("UI/UISprites")) return;
string tag = Path.GetFileName(Path.GetDirectoryName(assetPath));
//自动设置类型;
TextureImporter textureImporter = (TextureImporter)assetImporter;
textureImporter.textureType = TextureImporterType.Sprite;
textureImporter.wrapMode = TextureWrapMode.Clamp;
textureImporter.npotScale = TextureImporterNPOTScale.None;
textureImporter.isReadable = true;
textureImporter.mipmapEnabled = false;
textureImporter.maxTextureSize = 2048;
textureImporter.spritePackingTag = tag;
textureImporter.spriteImportMode = SpriteImportMode.Single;
}
}