Source, config, and docs only — UE template assets stay local to save storage. Co-authored-by: Cursor <cursoragent@cursor.com>
85 lines
2.5 KiB
C++
85 lines
2.5 KiB
C++
// Copyright VocationLife Project. All Rights Reserved.
|
|
|
|
#include "VocationTestWorldBuilder.h"
|
|
#include "MiningNode.h"
|
|
#include "VocationEnemy.h"
|
|
#include "Engine/StaticMeshActor.h"
|
|
#include "Components/StaticMeshComponent.h"
|
|
#include "Engine/StaticMesh.h"
|
|
#include "Engine/DirectionalLight.h"
|
|
#include "Engine/SkyLight.h"
|
|
#include "Components/DirectionalLightComponent.h"
|
|
#include "Components/SkyLightComponent.h"
|
|
#include "EngineUtils.h"
|
|
#include "Kismet/GameplayStatics.h"
|
|
#include "UObject/ConstructorHelpers.h"
|
|
|
|
AVocationTestWorldBuilder::AVocationTestWorldBuilder()
|
|
{
|
|
PrimaryActorTick.bCanEverTick = false;
|
|
}
|
|
|
|
void AVocationTestWorldBuilder::BeginPlay()
|
|
{
|
|
Super::BeginPlay();
|
|
if (bAutoBuildOnBeginPlay && GetWorld() && HasAuthority())
|
|
{
|
|
BuildTestWorld();
|
|
}
|
|
}
|
|
|
|
void AVocationTestWorldBuilder::BuildTestWorld()
|
|
{
|
|
UWorld* World = GetWorld();
|
|
if (!World)
|
|
{
|
|
return;
|
|
}
|
|
|
|
static ConstructorHelpers::FObjectFinder<UStaticMesh> PlaneMesh(TEXT("/Engine/BasicShapes/Plane.Plane"));
|
|
if (PlaneMesh.Succeeded())
|
|
{
|
|
FActorSpawnParameters SpawnParams;
|
|
SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
|
|
|
if (AStaticMeshActor* Floor = World->SpawnActor<AStaticMeshActor>(FVector::ZeroVector, FRotator::ZeroRotator, SpawnParams))
|
|
{
|
|
Floor->GetStaticMeshComponent()->SetStaticMesh(PlaneMesh.Object);
|
|
Floor->SetActorScale3D(FVector(20.f, 20.f, 1.f));
|
|
}
|
|
}
|
|
|
|
FActorSpawnParameters SpawnParams;
|
|
SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
|
|
|
World->SpawnActor<AMiningNode>(FVector(400.f, 0.f, 50.f), FRotator::ZeroRotator, SpawnParams);
|
|
World->SpawnActor<AMiningNode>(FVector(-350.f, 250.f, 50.f), FRotator::ZeroRotator, SpawnParams);
|
|
World->SpawnActor<AVocationEnemy>(FVector(800.f, 0.f, 100.f), FRotator(180.f, 0.f, 0.f), SpawnParams);
|
|
|
|
TArray<AActor*> FoundLights;
|
|
UGameplayStatics::GetAllActorsOfClass(World, ADirectionalLight::StaticClass(), FoundLights);
|
|
if (FoundLights.Num() == 0)
|
|
{
|
|
ADirectionalLight* Sun = World->SpawnActor<ADirectionalLight>();
|
|
if (Sun)
|
|
{
|
|
Sun->SetActorRotation(FRotator(-45.f, 45.f, 0.f));
|
|
if (UDirectionalLightComponent* Light = Sun->GetComponent())
|
|
{
|
|
Light->SetIntensity(6.f);
|
|
}
|
|
}
|
|
}
|
|
|
|
TArray<AActor*> FoundSkies;
|
|
UGameplayStatics::GetAllActorsOfClass(World, ASkyLight::StaticClass(), FoundSkies);
|
|
if (FoundSkies.Num() == 0)
|
|
{
|
|
ASkyLight* Sky = World->SpawnActor<ASkyLight>();
|
|
if (Sky && Sky->GetLightComponent())
|
|
{
|
|
Sky->GetLightComponent()->SetIntensity(1.f);
|
|
}
|
|
}
|
|
}
|