继承AssetPostprocessor
相关设置提前处理OnPreprocessTexture
导入后的处理OnPostprocessTexture
完整代码:
using Framework;
using UnityEditor;
using UnityEngine;
namespace Editor.Tools
{
public class ImportAssetSettings : AssetPostprocessor
{
private const string ISIMPORTED = "isImported";
private bool IsImported()
{
if (Application.isBatchMode) return true;
return !assetPath.StartsWith(Constants.ArtDirPath) || assetImporter.userData.EndsWith(ISIMPORTED);
}
private void OnPostprocessTexture(Texture2D texture)
{
assetImporter.userData = ISIMPORTED;
}
private void OnPreprocessTexture()
{
if(IsImported()) return;
TextureImporter textureImporter = (TextureImporter) assetImporter;
textureImporter.textureType = TextureImporterType.Sprite;
textureImporter.mipmapEnabled = false;
textureImporter.isReadable = false;
}
}
}