Version: 2021.3

EditorUtility.CollectDependencies

切换到手册
public static Object[] CollectDependencies (Object[] roots);

描述

计算并返回 roots 中列出的资源所依赖的所有资源的列表。


显示下一个示例的编辑器窗口。

using UnityEngine;
using UnityEditor;

public class CollectDependenciesExample : EditorWindow { static GameObject obj = null;

[MenuItem("Example/Collect Dependencies")] static void Init() { // Get existing open window or if none, make a new one: CollectDependenciesExample window = (CollectDependenciesExample)EditorWindow.GetWindow(typeof(CollectDependenciesExample)); window.Show(); }

void OnGUI() { obj = EditorGUI.ObjectField(new Rect(3, 3, position.width - 6, 20), "Find Dependency", obj, typeof(GameObject)) as GameObject;

if (obj) { Object[] roots = new Object[] { obj };

if (GUI.Button(new Rect(3, 25, position.width - 6, 20), "Check Dependencies")) Selection.objects = EditorUtility.CollectDependencies(roots); } else EditorGUI.LabelField(new Rect(3, 25, position.width - 6, 20), "Missing:", "Select an object first"); }

void OnInspectorUpdate() { Repaint(); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961