// 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 PlaneMesh(TEXT("/Engine/BasicShapes/Plane.Plane")); if (PlaneMesh.Succeeded()) { FActorSpawnParameters SpawnParams; SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; if (AStaticMeshActor* Floor = World->SpawnActor(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(FVector(400.f, 0.f, 50.f), FRotator::ZeroRotator, SpawnParams); World->SpawnActor(FVector(-350.f, 250.f, 50.f), FRotator::ZeroRotator, SpawnParams); World->SpawnActor(FVector(800.f, 0.f, 100.f), FRotator(180.f, 0.f, 0.f), SpawnParams); TArray FoundLights; UGameplayStatics::GetAllActorsOfClass(World, ADirectionalLight::StaticClass(), FoundLights); if (FoundLights.Num() == 0) { ADirectionalLight* Sun = World->SpawnActor(); if (Sun) { Sun->SetActorRotation(FRotator(-45.f, 45.f, 0.f)); if (UDirectionalLightComponent* Light = Sun->GetComponent()) { Light->SetIntensity(6.f); } } } TArray FoundSkies; UGameplayStatics::GetAllActorsOfClass(World, ASkyLight::StaticClass(), FoundSkies); if (FoundSkies.Num() == 0) { ASkyLight* Sky = World->SpawnActor(); if (Sky && Sky->GetLightComponent()) { Sky->GetLightComponent()->SetIntensity(1.f); } } }