美文网首页
2022-03-20【ue】TArray.Sort&Find:L

2022-03-20【ue】TArray.Sort&Find:L

作者: 持刀的要迟到了 | 来源:发表于2022-03-20 12:58 被阅读0次

Sort

    // Sort the vehicles by vehicle index, not strictly necessary, but this could
    // help to avoid bugs when referencing vehicles later.

    Vehicles.Sort([] (const ABaseVehicle& object1, const ABaseVehicle& object2)
        {
            return object1.GetVehicleIndex() < object2.GetVehicleIndex();
        });
    int curDepth = -1;
    std::function<void(TArray<SpanTreeNode*>)> SetDepthRecursive;
    SetDepthRecursive = [&curDepth, tree, &SetDepthRecursive](TArray<SpanTreeNode*> levelNodes)
    {
        curDepth++;

        for (auto item : levelNodes)
        {
            item->Depth = curDepth;
        }

        TArray<SpanTreeNode*> nextLevelNodes;
        for (auto item : tree)
        {
            if (item->Depth == -1) //还没确定深度的节点,需要查看是否是当前谁的孩子,还需要查看它是否反了。
            {
                for (auto item2 : levelNodes)
                {
                    if (item->ParentContext == item2->SelfContext)
                    {
                        //找到了,没反不需要翻转
                        item->ParentNode = item2;
                        item2->ChildrenNodes.Add(item);
                        nextLevelNodes.Add(item);
                        break;
                    }
                    else if (item->SelfContext == item2->SelfContext)
                    {
                        item->Flip(); //找到了,反了,翻转
                        item->ParentNode = item2;
                        item2->ChildrenNodes.Add(item);
                        nextLevelNodes.Add(item);
                        break;
                    }
                }
            }
        }

        if (nextLevelNodes.Num() > 0)
        {
            SetDepthRecursive(nextLevelNodes);
        }
    };

c++ - 'content' is not captured - Arduino Stack Exchange
c++ - Recursive lambda functions in C++11 - Stack Overflow

Find

Find Specific Element in TArray - Unreal Engine / Programming & Scripting - Unreal Engine Forums

    // 开上门
    if((openDirection & ECubeBaseDirection::n) == ECubeBaseDirection::n)
    {
        int _cubeCount = cubeCount;
        FTile* FoundEntry = tiles.FindByPredicate([&_cubeCount](const FTile& InItem)
        {
            return InItem.i == _cubeCount / 2 && InItem.j == _cubeCount - 1; 
        });
        if(FoundEntry)
        {
            FoundEntry->isOpen = true;
            FoundEntry->block->SetActive(false);
        }
    }

相关文章

网友评论

      本文标题:2022-03-20【ue】TArray.Sort&Find:L

      本文链接:https://www.haomeiwen.com/subject/pygodrtx.html