Unity ReferenceFinder插件 多选资源查找bug解决

GitHub地址


当选中多个资源 查找引用时,有的资源引用不显示,解决方法:

ReferenceFinderWindow脚本原来的 while(stack.Count > 0) { ... if (!memo.ContainsKey(current[0])) { ... } } 替换为下面这段。

csharp 复制代码
// 替换原来的 while(stack.Count > 0) { ... } 整段
var retryCount = new Dictionary<string, int>();
while (stack.Count > 0)
{
    var current = stack.Pop();
    string guid = current[0];
    int curDepth = int.Parse(current[1]);
    string parentGuid = current[2];

    // CreateTree 会在 memo 里返回已存在的节点或新建一个并加入 memo
    var child = CreateTree(guid, ref elementCount, curDepth, stack, memo);
    if (child == null)
        continue;

    if (string.IsNullOrEmpty(parentGuid))
    {
        // 直接挂到根(避免重复)
        if (root.children == null || !root.children.Contains(child))
            root.AddChild(child);
        continue;
    }

    // 父节点已存在,则直接挂上去(避免重复)
    if (memo.TryGetValue(parentGuid, out AssetViewItem parentItem))
    {
        if (parentItem.children == null || !parentItem.children.Contains(child))
            parentItem.AddChild(child);
        // 成功挂上,重试计数可清除(若有)
        if (retryCount.ContainsKey(guid)) retryCount.Remove(guid);
        continue;
    }
    else
    {
        // 父节点还不存在:重试逻辑(将当前项压回栈,等待父节点被创建)
        int attempts = 0;
        retryCount.TryGetValue(guid, out attempts);
        attempts++;
        retryCount[guid] = attempts;

        if (attempts <= 4) // 重试上限(可调整)
        {
            stack.Push(current); // 稍后再试一次
        }
        else
        {
            // 父节点长时间未出现 -> 降级把它挂到 root,避免死循环
            if (root.children == null || !root.children.Contains(child))
                root.AddChild(child);
            retryCount.Remove(guid);
            Debug.LogWarning($"ReferenceFinder: parent {parentGuid} for {guid} not found after retries, attached to root.");
        }
    }
}

思路:

不再在外面直接跳过 memo 已有项;改为 总是拿到节点(CreateTree 自身会返回已存在的 memo 项),然后尝试把它挂到当前父节点上(如果父节点还没创建则把当前项压回栈并记录重试次数,避免无限循环)。

加了个 retryCount 字典:若某节点连续多次尝试仍然找不到父节点,则把它挂到 root(降级处理),避免死循环。

相关推荐
GLDbalala4 小时前
Unity基于自定义管线实现经典经验光照模型
unity·游戏引擎
心疼你的一切6 小时前
Unity异步编程神器:Unitask库深度解析(功能+实战案例+API全指南)
深度学习·unity·c#·游戏引擎·unitask
呆呆敲代码的小Y8 小时前
【Unity 实用工具篇】 | Book Page Curl 快速实现翻书效果
游戏·unity·游戏引擎·u3d·免费游戏·翻书插件
AC梦21 小时前
unity中如何将UI上的字高清显示
ui·unity
这个软件需要设计一下1 天前
ninedata安装磁盘不足问题解决
运维·bug
热爱生活的五柒1 天前
cc-switch安装方法、介绍及遇到的bug
bug·cc-switch
Greenland_121 天前
Android 混淆与混淆后bug日志问题定位
android·bug
小贺儿开发1 天前
Unity3D 智慧城市管理平台
数据库·人工智能·unity·智慧城市·数据可视化
应用市场1 天前
踩坑记录:有符号整数位运算的那些隐蔽Bug——符号扩展、算术右移与补码
java·开发语言·bug
June bug2 天前
【领域知识】休闲游戏一次发版全流程:Google Play + Apple App Store
unity