UE4中Lambda的一些用法

跟Delegate一起用

FTimerDelegate TimerCallback;
TimerCallback.BindLambda([]
{
    // callback;
});

FTimerHandle Handle;
GetWorld()->GetTimerManager().SetTimer(Handle, TimerCallback, 5.0f, false);

UI回调事件

 SNew(SButton).OnClicked_Lambda([&]()
 {
     GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Button Clicked!"));
     return FReply::Handled();
 })

跨线程执行

        FFunctionGraphTask::CreateAndDispatchWhenReady([=]()
        {
            // game thread code
        }
        , TStatId(), nullptr, ENamedThreads::GameThread);

批量执行

void USkeletalMeshComponent::SetAllBodiesBelowSimulatePhysics( const FName& InBoneName, bool bNewSimulate, bool bIncludeSelf )
{
    int32 NumBodiesFound = ForEachBodyBelow(InBoneName, bIncludeSelf, /*bSkipCustomPhysicsType=*/ false, [bNewSimulate](FBodyInstance* BI)
    {
        BI->SetInstanceSimulatePhysics(bNewSimulate);
    });
...
}

猜你喜欢

转载自blog.csdn.net/xoyojank/article/details/52859518
今日推荐