官方API: https://docs.unity3d.com/ScriptReference/AssetPostprocessor.html
using UnityEngine;
using UnityEditor;
/// <summary>
/// 注意:自定义的AssetPostprocessor应该以dll的方式调用,可以确保即使脚本有编译错误,也可以始终执行它们
/// </summary>
public class CustomAssetPostprocessor : AssetPostprocessor
{
//模型导入之前调用
public void OnPreprocessModel()
{
Debug.Log("OnPreprocessModel=" + this.assetPath);
}
public void OnPostprocessModel(GameObject go)
{
Debug.Log("OnPostprocessModel=" + go.name);
}
//纹理导入之前调用,针对入到的纹理进行设置
public void OnPreprocessTexture()
{
Debug.Log("OnPreProcessTexture=" + this.assetPath);
//TextureImporter impor = this.assetImporter as TextureImporter;
//impor.textureFormat = TextureImporterFormat.ARGB32;
//impor.maxTextureSize = 512;
//impor.textureType = TextureImporterType.Default;
//impor.mipmapEnabled = false;
}
public void OnPostprocessTexture(Texture2D tex)
{
Debug.Log("OnPostProcessTexture=" + this.assetPath);
}
public void OnPostprocessAudio(AudioClip clip)
{
}
public void OnPreprocessAudio()
{
AudioImporter audio = this.assetImporter as AudioImporter;
//audio. = AudioCompressionFormat.MP3;
}
//所有的资源的导入,删除,移动,都会调用此方法,注意,这个方法是static的
public static void OnPostprocessAllAssets(string[] importedAsset, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
{
Debug.Log("OnPostprocessAllAssets");
foreach (string str in importedAsset)
{
Debug.Log("importedAsset = " + str);
}
foreach (string str in deletedAssets)
{
Debug.Log("deletedAssets = " + str);
}
foreach (string str in movedAssets)
{
Debug.Log("movedAssets = " + str);
}
foreach (string str in movedFromAssetPaths)
{
Debug.Log("movedFromAssetPaths = " + str);
}
}
}