현재 TileGame 의 두 Tile을 선택하고 교환 할 수 있다. 하지만 Tile 게임에서 상하좌우 상태에서만 교환이 되기 때문에 그 부분을 수정 하겠다
인접한 타일끼리만 교환 가능
아직은 정상 작동 하지않는다
비동기 작업의 순서 문제
비동기 작업을 유지하면서 해결하는 방안
비동기작업Ver.
ATileGrid::ATileGrid()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
GridWidth = 8;
GridHeigh = 8;
TileSpacing = 100;
TileArray.SetNum(GridWidth * GridHeigh);
// 1차원 배열로 메모리 할당 8*8 형태
}
void ATileGrid::InitializeGrid()
{
// 가능한 TileType 리스트
TArray<FName> TileTypes =
{
FName("Cone"),
FName("Cube"),
FName("Cylinder"),
FName("Sphere"),
FName("Capsule"),
FName("Pyramid")
};
for (int32 x = 0; x < GridWidth; ++x)
{
for (int32 y = 0; y < GridHeigh; ++y)
{
// 비동기적으로 타일을 생성
AsyncTask(ENamedThreads::GameThread, [this, x, y, TileTypes]()
{
// 타일 타입을 핸덤하게 결정 ( 비동기 작업 )
FName RandomTileType = TileTypes[FMath::RandRange(0, TileTypes.Num() - 1)];
// 게임 스레드에서 타일 생성과 외형 설정을 처리
AsyncTask(ENamedThreads::GameThread, [this, x, y, RandomTileType]()
{
if (!TileClass)
{
UE_LOG(LogTemp, Warning, TEXT("TileClass is not Valid "));
return;
}
FActorSpawnParameters SpawnParams;
ATile* NewTile = GetWorld()->SpawnActor<ATile>(TileClass, SpawnParams);
if (NewTile)
{
// 타일 그리드 참조
NewTile->TileGrid = this;
// 타일의 그리상의 위치
NewTile->TilePosition = FVector2D(x, y);
// 생성된 타일의 타일 설정
NewTile->TileType = RandomTileType;
// 타일 종류에 따라서 외형 업데이트
NewTile->UpdateTileAppearance();
// 타일을 TIleGrid의 자식으로 부착
NewTile->AttachToActor(this, FAttachmentTransformRules::KeepRelativeTransform);
// 타일을 그리드에 배치
FVector RelativeLocation = FVector(x * TileSpacing, y * TileSpacing, 0.0f);
NewTile->SetActorRelativeLocation(RelativeLocation);
// 그리드에 타일 저장
SetTile(x, y, NewTile);
UE_LOG(LogTemp, Warning, TEXT("Tile Create at [ %d, %d ] with type %s "), x, y, *RandomTileType.ToString());
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Failed to Spawn Tile at [ %d, %d ]"), x, y);
}
});
});
}
}
// 가능한 TileType 리스트
}