unity已知一个资源的路径,查找其依赖项

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

public class Test
{
    [MenuItem("BuildTool/Lugs")]
    static void LugsTest()
    {
        string assetpath = "Assets/UI/Prefab/ui_login/ui_login.prefab";
        string[] a = GetAssetDependencies(assetpath);
        for (int i = 0, iMax = a.Length; i < iMax; ++i)
        {
            Debug.Log(a[i]);
        }
    }

    static string[] GetAssetDependencies(string assetPath)
    {
        if (!File.Exists(assetPath))
            return null;
        string[] dependecies = AssetDatabase.GetDependencies(assetPath);
        return dependecies;
    }
}

执行结果:

原文地址:https://www.cnblogs.com/luguoshuai/p/11367817.html