监听资源编辑——AssetModificationProcessor

作者:追风剑情 发布于:2017-11-8 17:39 分类:Unity3d

示例


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;
    }
}


测试

1111.png

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号