栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Unity Editor 查找资源依赖、反向查找资源依赖Dependencies

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Unity Editor 查找资源依赖、反向查找资源依赖Dependencies

  

    [MenuItem("Assets/查找选中资源依赖关系",false, 0)]
    public static void FindDependencies()
    {
        foreach (var guid in Selection.assetGUIDs)
        {
            string path = AssetDatabase.GUIDToAssetPath(guid);
            foreach (var dependenciePath in AssetDatabase.GetDependencies(path, false))
            {
                if(path != dependenciePath && !dependenciePath.Contains("cs"))
                    Debug.LogError(string.Format("path = {0} 依赖 > {1}", path, dependenciePath));
            }
        }
        Debug.Log("查找依赖结束");
    }

    [MenuItem("Assets/查找选中资源反向依赖关系", false, 1)]
    public static void FindReverseDependencies()
    {
        Dictionary> dDependencies = new Dictionary>();

        foreach (var guid in Selection.assetGUIDs)
        {
            string t = AssetDatabase.GUIDToAssetPath(guid);
            dDependencies.Add(t, new List());
        }

        string[] guids = AssetDatabase.FindAssets("t:Prefab t:Material t:Scene");
        for (int i = 0; i < guids.Length; i++)
        {
            string guid = guids[i];
            string path = AssetDatabase.GUIDToAssetPath(guid);

            if (EditorUtility.DisplayCancelableProgressBar("资源依赖关系查找中", path, (float)(i + 1) / guids.Length))
            {
                EditorUtility.ClearProgressBar();
                return;
            }

            foreach (var dependenciePath in AssetDatabase.GetDependencies(path, false))
            {
                if (path != dependenciePath)
                {
                    if (dDependencies.TryGetValue(dependenciePath, out List list))
                    {
                        list.Add(path);
                    }
                }
            }
        }

        foreach (var kv in dDependencies)
        {
            kv.Value.ForEach((dependenciePath) =>
            {
                Debug.LogError(string.Format("path = {0} 被 > {1} 依赖", kv.Key, dependenciePath));
            });
        }


        EditorUtility.ClearProgressBar();
        Debug.Log("查找依赖结束");
    }

查找资源依赖、反向查找资源被依赖关系。

该工具的意义用于打AB的时候 可以查找跨模块引用的资源并列举出来!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/979275.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号