获取对象依赖关系

作者:追风剑情 发布于:2017-12-21 21:14 分类:Unity3d

手动查看对象依赖关系

11111.png

2222.png

代码获取对象依赖关系

using UnityEngine;
using UnityEditor;
using System;
using System.IO;
using System.Collections;

public class MenuEditor {

    [MenuItem("Tool/EditorUtility.CollectDependencies")]
    static void CollectDependencies()
	{
        Debug.Log("Test EditorUtility.CollectDependencies()");
        UnityEngine.Object obj = Selection.activeObject;
        //这个方法会返回很多重复数据
        UnityEngine.Object[] dep_objs = EditorUtility.CollectDependencies(new UnityEngine.Object[] { obj });
        if (null == dep_objs || dep_objs.Length == 0) {
            Debug.Log("当前选择的对象不存在依赖项");
            return;
        }
        for (int i = 0; i < dep_objs.Length; i++) {
            string path = AssetDatabase.GetAssetPath(dep_objs[i]);
            Debug.Log(path);
        }
	}

    [MenuItem("Tool/AssetDatabase.GetDependencies")]
    static void GetDependencies()
    {
        Debug.Log("Test AssetDatabase.GetDependencies()");
        UnityEngine.Object obj = Selection.activeObject;
        //这个方法不会返回重复数据
        string[] paths = AssetDatabase.GetDependencies(new string[] { AssetDatabase.GetAssetPath(obj) });
        if (null == paths || paths.Length == 0) {
            Debug.Log("当前选择的对象不存在依赖项");
            return;
        }
        foreach (string path in paths) {
            Debug.Log(path);
        }
    }
}

测试

4444.png

333.png

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号