38 lines
1.3 KiB
C++
38 lines
1.3 KiB
C++
// All rights reserved.
|
|
|
|
|
|
#include "SpawnManager.h"
|
|
|
|
// Sets default values
|
|
ASpawnManager::ASpawnManager()
|
|
{
|
|
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
|
PrimaryActorTick.bCanEverTick = false;
|
|
|
|
}
|
|
|
|
void ASpawnManager::GenerateBoard(const TSubclassOf<ALevelTemplate> Template) {
|
|
FVector ActorLocation = this->GetActorLocation();
|
|
CurrentLevel = GetWorld()->SpawnActor<ALevelTemplate>(Template, this->GetActorTransform());
|
|
UPaperTileMapComponent* Tilemap = CurrentLevel->Template;
|
|
|
|
TArray<TSubclassOf<ABuildingBlock>> Classes;
|
|
|
|
for (int32 i = 0; i < BlocksY; i++) {
|
|
for (int32 o = 0; o < BlocksX; o++) {
|
|
// Make transform
|
|
FTransform SpawnTransform;
|
|
SpawnTransform.SetLocation(FVector((ActorLocation.X - (Distance * BlocksX / 2) + (o * Distance)), (ActorLocation.Y - (Distance * (BlocksY / 2)) + (i * Distance)), ActorLocation.Z));
|
|
|
|
// Spawn block
|
|
int32 TileId = Tilemap->GetTile(i, o, 0).GetTileIndex();
|
|
TSubclassOf<ABuildingBlock> TileClass = *BlockTemplates.Find(TileId);
|
|
ABuildingBlock* ThisBlock = GetWorld()->SpawnActor<ABuildingBlock>(TileClass, SpawnTransform);
|
|
ThisBlock->Index = (10 * i) + o;
|
|
if (ThisBlock->HasVariants) {
|
|
ThisBlock->Variant = FMath::RandRange(1, MaxVariants);
|
|
}
|
|
ThisBlock->FadeIn();
|
|
}
|
|
}
|
|
} |