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(降级处理),避免死循环。

相关推荐
小贺儿开发5 小时前
Unity3D 心理沙盘互动演示
unity·ai·pdf·人机交互·工具·互动·心理沙盘
CuPhoenix7 小时前
【沧海拾昧】Unity 导入中文字体文字缺失的解决方法
unity
南無忘码至尊8 小时前
Unity学习90天-第1天-认识Transform + 坐标系
学习·unity·游戏引擎
南無忘码至尊8 小时前
Unity学习90天-第1天-认识Unity并书写我们的第一个脚本
学习·unity·游戏引擎
风酥糖9 小时前
Godot游戏练习01-第26节-轮次结束后弹出升级选项
游戏·游戏引擎·godot
雪域迷影9 小时前
Hazel游戏引擎结构分析
c++·游戏引擎·hazel
万粉变现经纪人9 小时前
如何解决 pip install tensorflow-gpu 报错 未检测到 CUDA 驱动 问题
人工智能·python·深度学习·aigc·tensorflow·bug·pip
Nuopiane11 小时前
C#基础(1)堆栈、GC与Marshal
unity·c#
weixin_4093831218 小时前
godot创建两种敌人僵尸 一种吐舌头 一种在角色脚下生成圆形伤害圈 两种僵尸均继承enemy脚本 理解继承
游戏引擎·godot
mxwin1 天前
Unity Shader 跨平台兼容性:处理纹理坐标翻转与精度差异
unity·游戏引擎