// Fill out your copyright notice in the Description page of Project Settings.
#if WITH_EDITOR
#include "ComponentAssetBroker.h"
#include "Kismet2/BlueprintEditorUtils.h"
#endif
#include "Engine/SimpleConstructionScript.h"
#include "Engine/Blueprint.h"
#include "Engine/SCS_Node.h"
#include "Templates/Casts.h"
#include "Components/StaticMeshComponent.h"
#include "Engine/StaticMesh.h"
void UK::AddBlueprintComponent(UObject* Asset, UBlueprint* Blueprint, FVector Scale3D, FRotator Rotator, bool ShadowEnabled, bool bIsShadow)
{
#if WITH_EDITOR
TSubclassOf<UActorComponent> ComponentClass = FComponentAssetBrokerage::GetPrimaryComponentForAsset(Asset->GetClass());
USCS_Node* NewNode = Blueprint->SimpleConstructionScript->CreateNode(ComponentClass);
FComponentAssetBrokerage::AssignAssetToComponent(NewNode->ComponentTemplate, Asset);
NewNode->SetVariableName(*Asset->GetName());
Blueprint->SimpleConstructionScript->AddNode(NewNode);
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(Blueprint);
#endif
}
void UK::AddBlueprintActorComponent(UObject * Asset, UBlueprint * Blueprint, FVector Location, FRotator Rotator, FVector Scale3D)
{
#if WITH_EDITOR
USCS_Node* NewNode = Blueprint->SimpleConstructionScript->CreateNode(UChildActorComponent::StaticClass());
FComponentAssetBrokerage::AssignAssetToComponent(NewNode->ComponentTemplate, Asset);
UChildActorComponent* t = Cast<UChildActorComponent>(NewNode->ComponentTemplate);
t->SetWorldLocation(Location);
t->SetWorldRotation(Rotator);
t->SetWorldScale3D(Scale3D);
Blueprint->SimpleConstructionScript->AddNode(NewNode);
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(Blueprint);
#endif
}
FString UK::GetParamModelName(UBlueprint* Blueprint)
{
#if WITH_EDITOR
TArray<USCS_Node*> nodes = Blueprint->SimpleConstructionScript->GetAllNodes();
UStaticMeshComponent* ChildTemplate = Cast<UStaticMeshComponent>(nodes[0]->ComponentTemplate);
FString pname = ChildTemplate->GetStaticMesh()->GetName();
return pname;
#endif
return FString();
//UE_LOG(LogTemp, Error, TEXT("%s"),*pname);
}
TArray<FString> UK::GetBluepirntComponentsName(UBlueprint* Blueprint)
{
#if WITH_EDITOR
TArray<FString> result;
TArray<USCS_Node*> nodes = Blueprint->SimpleConstructionScript->GetAllNodes();
for (USCS_Node* node : nodes)
{
UStaticMeshComponent* ChildTemplate = Cast<UStaticMeshComponent>(node->ComponentTemplate);
FString pname = ChildTemplate->GetStaticMesh()->GetName();
result.Add(pname);
}
return result;
#endif
TArray<FString> a;
return a;
//UE_LOG(LogTemp, Error, TEXT("%s"), "abc");
}