手动查看对象依赖关系
代码获取对象依赖关系
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);
}
}
}
测试