示例
using UnityEngine;
using UnityEditor;
using System.Collections;
/// <summary>
/// 参考 http://www.xuanyusong.com/archives/3535
/// 监听资源修改、删除、移动
/// </summary>
public class CAssetModificationProcessor : AssetModificationProcessor
{
// 是否已被编辑器打开
public static bool IsOpenForEdit (string assetPath, out string message)
{
message = "";
return false;
}
// 创建前
public static void OnWillCreateAsset(string path)
{
Debug.Log("OnWillCreateAsset " + path);
}
// 删除前
public static AssetDeleteResult OnWillDeleteAsset (string assetPath, RemoveAssetOptions option)
{
Debug.Log("OnWillDeleteAsset " + assetPath);
return AssetDeleteResult.DidNotDelete;
}
// 移动、重命名 前
public static AssetMoveResult OnWillMoveAsset (string oldPath, string newPath)
{
AssetMoveResult result = AssetMoveResult.DidNotMove;
Debug.Log("OnWillMoveAsset from: " + oldPath + " to: " + newPath);
return result;
}
// 保存前
public static string[] OnWillSaveAssets(string[] paths)
{
Debug.Log("OnWillSaveAssets");
foreach (string path in paths)
Debug.Log(path);
return paths;
}
}
测试