Added WingActorComponent
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
#include "WingActorComponent.h"
|
||||
#include "WingUtils.h"
|
||||
#include "Engine/Blueprint.h"
|
||||
#include "Engine/SCS_Node.h"
|
||||
#include "Engine/SimpleConstructionScript.h"
|
||||
#include "Components/ActorComponent.h"
|
||||
#include "Components/SceneComponent.h"
|
||||
#include "GameFramework/Actor.h"
|
||||
#include "Kismet2/BlueprintEditorUtils.h"
|
||||
|
||||
FString FWingActorComponent::GetName() const
|
||||
{
|
||||
if (SCSNode) return WingUtils::FormatName(SCSNode);
|
||||
if (NativeComponent) return WingUtils::FormatName(NativeComponent);
|
||||
return FString();
|
||||
}
|
||||
|
||||
FString FWingActorComponent::GetClassName() const
|
||||
{
|
||||
if (SCSNode)
|
||||
return SCSNode->ComponentClass ? WingUtils::FormatName(SCSNode->ComponentClass) : TEXT("None");
|
||||
if (NativeComponent)
|
||||
return WingUtils::FormatName(NativeComponent->GetClass());
|
||||
return FString();
|
||||
}
|
||||
|
||||
FString FWingActorComponent::GetParentName() const
|
||||
{
|
||||
if (SCSNode)
|
||||
{
|
||||
if (SCSNode->ParentComponentOrVariableName != NAME_None)
|
||||
return WingUtils::SanitizeName(SCSNode->ParentComponentOrVariableName);
|
||||
return FString();
|
||||
}
|
||||
if (NativeComponent)
|
||||
{
|
||||
if (USceneComponent* Scene = Cast<USceneComponent>(NativeComponent))
|
||||
if (USceneComponent* Parent = Scene->GetAttachParent())
|
||||
return WingUtils::FormatName(Parent);
|
||||
return FString();
|
||||
}
|
||||
return FString();
|
||||
}
|
||||
|
||||
bool FWingActorComponent::IsOwnedBy(const UBlueprint* BP) const
|
||||
{
|
||||
return BP && BP->GeneratedClass == Owner;
|
||||
}
|
||||
|
||||
TArray<FWingActorComponent> FWingActorComponent::GetAll(UBlueprint* BP)
|
||||
{
|
||||
TArray<FWingActorComponent> Result;
|
||||
if (!BP) return Result;
|
||||
|
||||
UClass* GenClass = BP->GeneratedClass;
|
||||
if (!GenClass) return Result;
|
||||
|
||||
// Native components from CDO
|
||||
if (AActor* CDO = Cast<AActor>(GenClass->GetDefaultObject()))
|
||||
{
|
||||
UClass* NativeClass = FBlueprintEditorUtils::FindFirstNativeClass(GenClass);
|
||||
TArray<UActorComponent*> NativeComponents;
|
||||
CDO->GetComponents(NativeComponents);
|
||||
for (UActorComponent* Comp : NativeComponents)
|
||||
Result.Emplace(Comp, NativeClass);
|
||||
}
|
||||
|
||||
// SCS nodes, walking hierarchy from oldest ancestor to current BP
|
||||
TArray<UBlueprint*> Hierarchy;
|
||||
UBlueprint::GetBlueprintHierarchyFromClass(GenClass, Hierarchy);
|
||||
for (int32 i = Hierarchy.Num() - 1; i >= 0; --i)
|
||||
{
|
||||
UBlueprint* WalkBP = Hierarchy[i];
|
||||
if (!WalkBP->SimpleConstructionScript) continue;
|
||||
UClass* OwnerClass = WalkBP->GeneratedClass;
|
||||
for (USCS_Node* Node : WalkBP->SimpleConstructionScript->GetAllNodes())
|
||||
Result.Emplace(Node, OwnerClass);
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "WingUtils.h"
|
||||
#include "WingActorComponent.h"
|
||||
#include "WingJson.h"
|
||||
#include "WingTypes.h"
|
||||
#include "WingServer.h"
|
||||
@@ -215,6 +216,11 @@ FString WingUtils::FormatName(const FBPInterfaceDescription &IFace)
|
||||
return FormatName(IFace.Interface);
|
||||
}
|
||||
|
||||
FString WingUtils::FormatName(const FWingActorComponent &Comp)
|
||||
{
|
||||
return Comp.GetName();
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Formatting other things
|
||||
// ============================================================
|
||||
|
||||
Reference in New Issue
Block a user