官方API: https://docs.unity3d.com/ScriptReference/AssetPostprocessor.html
1using UnityEngine; 2using UnityEditor; 3 4/// <summary> 5/// 注意:自定义的AssetPostprocessor应该以dll的方式调用,可以确保即使脚本有编译错误,也可以始终执行它们 6/// </summary> 7public class CustomAssetPostprocessor : AssetPostprocessor 8{ 9 //模型导入之前调用 10 public void OnPreprocessModel() 11 { 12 Debug.Log("OnPreprocessModel=" + this.assetPath); 13 } 14 15 public void OnPostprocessModel(GameObject go) 16 { 17 Debug.Log("OnPostprocessModel=" + go.name); 18 } 19 20 //纹理导入之前调用,针对入到的纹理进行设置 21 public void OnPreprocessTexture() 22 { 23 Debug.Log("OnPreProcessTexture=" + this.assetPath); 24 //TextureImporter impor = this.assetImporter as TextureImporter; 25 //impor.textureFormat = TextureImporterFormat.ARGB32; 26 //impor.maxTextureSize = 512; 27 //impor.textureType = TextureImporterType.Default; 28 //impor.mipmapEnabled = false; 29 30 } 31 32 public void OnPostprocessTexture(Texture2D tex) 33 { 34 Debug.Log("OnPostProcessTexture=" + this.assetPath); 35 } 36 37 38 public void OnPostprocessAudio(AudioClip clip) 39 { 40 41 } 42 43 public void OnPreprocessAudio() 44 { 45 AudioImporter audio = this.assetImporter as AudioImporter; 46 //audio. = AudioCompressionFormat.MP3; 47 } 48 49 //所有的资源的导入,删除,移动,都会调用此方法,注意,这个方法是static的 50 public static void OnPostprocessAllAssets(string[] importedAsset, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) 51 { 52 Debug.Log("OnPostprocessAllAssets"); 53 foreach (string str in importedAsset) 54 { 55 Debug.Log("importedAsset = " + str); 56 } 57 foreach (string str in deletedAssets) 58 { 59 Debug.Log("deletedAssets = " + str); 60 } 61 foreach (string str in movedAssets) 62 { 63 Debug.Log("movedAssets = " + str); 64 } 65 foreach (string str in movedFromAssetPaths) 66 { 67 Debug.Log("movedFromAssetPaths = " + str); 68 } 69 } 70}