可以监听Unity Project面板下,所有资源的变化(导入,删除,重载)
using UnityEngine; using UnityEditor; class MyAllPostprocessor : AssetPostprocessor { static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { foreach (string str in importedAssets) { Debug.Log("Reimported Asset: " + str); } foreach (string str in deletedAssets) { Debug.Log("Deleted Asset: " + str); } for (int i = 0; i < movedAssets.Length; i++) { Debug.Log("Moved Asset: " + movedAssets[i] + " from: " + movedFromAssetPaths[i]); } } }
也可以只关注制定类型资源的导入如
void OnPostprocessModel(GameObject g) { }
API地址 :https://docs.unity3d.com/2019.4/Documentation/ScriptReference/AssetPostprocessor.html
依赖此接口可以制作 资源导入后自动检查纠错 等相关工具
文章评论