Files
Fortis/Source/FORTIS_Taktika/Private/ResComFloorManager.cpp
T
2022-10-26 18:38:40 +05:00

174 lines
4.5 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#include "ResComFloorManager.h"
// Sets default values
AResComFloorManager::AResComFloorManager()
{
// 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;
}
// Called when the game starts or when spawned
void AResComFloorManager::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AResComFloorManager::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void AResComFloorManager::AddPack(const FFloorPack& pack)
{
packs.Add(pack);
}
void AResComFloorManager::AddLevelToPack(FApartmentLocation loc, FFloorLevelStreaming level)
{
FFloorPack pack;
if (GetPack(loc, pack))
{
UE_LOG(LogTemp, Warning, TEXT("COUNT: %d"), pack.levels.Num());
pack.levels.Add(level);
}
else
{
pack.location = loc;
pack.levels.Add(level);
AddPack(pack);
}
}
bool AResComFloorManager::GetPack(FApartmentLocation loc, FFloorPack* pack)
{
for (int i = 0; i < packs.Num(); ++i)
{
if (packs[i].location == loc)
{
pack = &(packs[i]);
return true;
}
}
return false;
}
bool AResComFloorManager::GetPack(FApartmentLocation loc, FFloorPack& pack) const
{
for (auto& packCurr : packs)
{
if (packCurr.location == loc)
{
pack = packCurr;
return true;
}
}
return false;
}
//bool AResComFloorManager::LoadPack(FApartmentLocation loc, const FOnPreview& delegatePreview, const FOnShouldBeVisible& delegateShouldBeVisible, const FOnShouldBeLoaded& delegateShouldBeLoaded)
bool AResComFloorManager::LoadPack(FApartmentLocation loc, const FOnLoaded& delegateOnLoaded)
{
FFloorPack* pack = nullptr;
if (!GetPack(loc, pack))
return false;
OnLoaded = delegateOnLoaded;
//OnPreview = delegatePreview;
//OnShouldBeVisible = delegateShouldBeVisible;
//OnShouldBeLoaded = delegateShouldBeLoaded;
FVector Location(0.0f, 0.0f, 0.0f);
FRotator Rotation(0.0f, 0.0f, 0.0f);
FActorSpawnParameters SpawnInfo;
GetWorld()->SpawnActor<AResComLevelPackLoader>(Location, Rotation, SpawnInfo);
return true;
}
bool AResComFloorManager::UnloadPack(FApartmentLocation loc, const FOnPreview& delegatePreview, const FOnShouldBeVisible& delegateShouldBeVisible, const FOnShouldBeLoaded& delegateShouldBeLoaded)
{
FFloorPack pack;
if (!GetPack(loc, pack))
return false;
FLatentActionInfo info;
//for (auto& level : pack.levelsPreview)
//{
// UGameplayStatics::UnloadStreamLevel(this,* level, info, false);
// //Streamlevel
//}
//for (auto& level : pack.levelsShouldBeVisible)
//{
// UGameplayStatics::UnloadStreamLevel(this, *level, info, false);
//}
//for (auto& level : pack.levelsShouldBeLoaded)
//{
// UGameplayStatics::UnloadStreamLevel(this, *level, info, false);
//}
OnPreview = delegatePreview;
OnShouldBeVisible = delegateShouldBeVisible;
OnShouldBeLoaded = delegateShouldBeLoaded;
return true;
}
void AResComFloorManager::OnLevelPreview()
{
OnPreview.Execute();
}
void AResComFloorManager::OnLevelVisible()
{
OnShouldBeVisible.Execute();
}
void AResComFloorManager::OnLevelLoaded()
{
OnShouldBeLoaded.Execute();
}
TArray<ULevelStreaming*> AResComFloorManager::GetStreamingLevels(const UObject* WorldContextObject)
{
TArray<ULevelStreaming*> levels;
UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull);
for (ULevelStreaming* LevelStreaming : World->GetStreamingLevels())
{
levels.Push(LevelStreaming);
}
return levels;
}
//ULevelStreaming* UGameplayStatics::GetStreamingLevel(const UObject* WorldContextObject, FName InPackageName)
//{
// if (InPackageName != NAME_None)
// {
// if (UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull))
// {
// FString SearchPackageName = FStreamLevelAction::MakeSafeLevelName(InPackageName, World);
// if (FPackageName::IsShortPackageName(SearchPackageName))
// {
// // Make sure MyMap1 and Map1 names do not resolve to a same streaming level
// SearchPackageName = TEXT("/") + SearchPackageName;
// }
//
// for (ULevelStreaming* LevelStreaming : World->GetStreamingLevels())
// {
// // We check only suffix of package name, to handle situations when packages were saved for play into a temporary folder
// // Like Saved/Autosaves/PackageName
// if (LevelStreaming && LevelStreaming->GetWorldAssetPackageName().EndsWith(SearchPackageName, ESearchCase::IgnoreCase))
// {
// return LevelStreaming;
// }
// }
// }
// }
//
// return NULL;
//}