You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#jira UETOOL-3823 #rb brooke.hubert #preflight 6109d1e9b4288d0001acb7ef #ROBOMERGE-SOURCE: CL 17055606 in //UE5/Main/... #ROBOMERGE-BOT: STARSHIP (Main -> Release-Engine-Test) (v850-17047176) [CL 17055619 by michael balzer in ue5-release-engine-test branch]
132 lines
3.3 KiB
C++
132 lines
3.3 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "ToolBuilderUtil.h"
|
|
#include "CoreMinimal.h"
|
|
#include "Algo/Accumulate.h"
|
|
#include "GameFramework/Actor.h"
|
|
#include "Engine/Selection.h"
|
|
#include "Components/StaticMeshComponent.h"
|
|
|
|
int ToolBuilderUtil::CountComponents(const FToolBuilderState& InputState, const TFunction<bool(UActorComponent*)>& Predicate)
|
|
{
|
|
int nTypedComponents{};
|
|
|
|
if (InputState.SelectedComponents.Num() > 0)
|
|
{
|
|
nTypedComponents = Algo::CountIf(InputState.SelectedComponents, Predicate);
|
|
}
|
|
else
|
|
{
|
|
nTypedComponents =
|
|
Algo::TransformAccumulate(InputState.SelectedActors,
|
|
[&Predicate](AActor* Actor)
|
|
{
|
|
return Algo::CountIf(Actor->GetComponents(), Predicate);
|
|
},
|
|
0);
|
|
}
|
|
return nTypedComponents;
|
|
}
|
|
|
|
|
|
|
|
|
|
UActorComponent* ToolBuilderUtil::FindFirstComponent(const FToolBuilderState& InputState, const TFunction<bool(UActorComponent*)>& Predicate)
|
|
{
|
|
if (InputState.SelectedComponents.Num() > 0)
|
|
{
|
|
UActorComponent* const* ComponentPtr = InputState.SelectedComponents.FindByPredicate(Predicate);
|
|
if (ComponentPtr)
|
|
{
|
|
return *ComponentPtr;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for ( AActor* Actor : InputState.SelectedActors )
|
|
{
|
|
UActorComponent* const* ComponentPtr = Algo::FindByPredicate(Actor->GetComponents(), Predicate);
|
|
if (ComponentPtr)
|
|
{
|
|
return *ComponentPtr;
|
|
}
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
|
|
|
|
|
|
TArray<UActorComponent*> ToolBuilderUtil::FindAllComponents(const FToolBuilderState& InputState, const TFunction<bool(UActorComponent*)>& Predicate)
|
|
{
|
|
if (InputState.SelectedComponents.Num() > 0)
|
|
{
|
|
return InputState.SelectedComponents.FilterByPredicate(Predicate);
|
|
}
|
|
else
|
|
{
|
|
return Algo::TransformAccumulate(InputState.SelectedActors,
|
|
[&Predicate](AActor* Actor)
|
|
{
|
|
TInlineComponentArray<UActorComponent*> ActorComponents;
|
|
Actor->GetComponents(ActorComponents);
|
|
return ActorComponents.FilterByPredicate(Predicate);
|
|
},
|
|
TArray<UActorComponent*>{},
|
|
[](TArray<UActorComponent*> FoundComponents, TArray<UActorComponent*> ActorComponents)
|
|
{
|
|
FoundComponents.Insert(MoveTemp(ActorComponents), FoundComponents.Num());
|
|
return FoundComponents;
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
void ToolBuilderUtil::EnumerateComponents(const FToolBuilderState& InputState, TFunctionRef<void(UActorComponent*)> ComponentFunc)
|
|
{
|
|
if (InputState.SelectedComponents.Num() > 0)
|
|
{
|
|
for (UActorComponent* Component : InputState.SelectedComponents)
|
|
{
|
|
ComponentFunc(Component);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (AActor* Actor : InputState.SelectedActors)
|
|
{
|
|
Actor->ForEachComponent(true,
|
|
[&ComponentFunc](UActorComponent* Component) {
|
|
ComponentFunc(Component);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
int32 ToolBuilderUtil::CountActors(const FToolBuilderState& InputState, const TFunction<bool(AActor*)>& Predicate)
|
|
{
|
|
return Algo::CountIf(InputState.SelectedActors, Predicate);
|
|
}
|
|
|
|
|
|
AActor* ToolBuilderUtil::FindFirstActor(const FToolBuilderState& InputState, const TFunction<bool(AActor*)>& Predicate)
|
|
{
|
|
AActor* const* Actor = InputState.SelectedActors.FindByPredicate(Predicate);
|
|
if (Actor)
|
|
{
|
|
return *Actor;
|
|
}
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
TArray<AActor*> ToolBuilderUtil::FindAllActors(const FToolBuilderState& InputState, const TFunction<bool(AActor*)>& Predicate)
|
|
{
|
|
return InputState.SelectedActors.FilterByPredicate(Predicate);
|
|
}
|
|
|