Created
December 3, 2019 05:33
-
-
Save hexagit/f9379ab1411eade3b6759dc23fcc1d33 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UCLASS() | |
class ALevelControl : public AActor | |
{ | |
GENERATED_BODY() | |
public: | |
ALevelControl(); | |
// Called every frame | |
virtual void Tick( float DeltaTime ) override; | |
UFUNCTION() | |
void Completed(); // <- これが完了時に呼び出される関数です。上にUFUNCTION()の設定が必ず要ります。 | |
void LoadLevel(const FName& level); | |
void UnloadLevel(const FName& level); | |
bool ShowLevel(const FName& level) const; | |
bool HideLevel(const FName& level) const; | |
bool IsCompleted() const; | |
private: | |
FLatentActionInfo LatentAction; | |
bool Complete; | |
}; | |
ALevelControl::ALevelControl() | |
{ | |
LatentAction.CallbackTarget = this; | |
LatentAction.ExecutionFunction = "Completed"; // <- 完了時に呼び出される関数名を設定 | |
LatentAction.UUID = 1; | |
LatentAction.Linkage = 0; | |
} | |
void ALevelControl::Completed() | |
{ | |
Complete = true; | |
} | |
// ロードレベル | |
void ALevelControl::LoadLevel(const FName& level) | |
{ | |
Complete = false; | |
UGameplayStatics::LoadStreamLevel( this, level, false, false, LatentAction ); | |
} | |
// アンロードレベル | |
void ALevelControl::UnloadLevel(const FName& level) | |
{ | |
Complete = false; | |
UGameplayStatics::UnloadStreamLevel( this, level, LatentAction, false ); | |
} | |
// レベルの表示(trueで完了、falseで処理中) | |
bool ALevelControl::ShowLevel(const FName& level) const | |
{ | |
auto levelstream = UGameplayStatics::GetStreamingLevel( GetWorld(), level ); | |
check(levelstream != nullptr); | |
levelstream->SetShouldBeVisible( true ); | |
return levelstream->IsLevelVisible(); // 処理簡略の為SetShouldBeVisible関数とIsLevelVisible関数が一緒に実行されていますが分けた方がすっきりします | |
} | |
// レベルの非表示(trueで完了、falseで処理中) | |
bool ALevelControl::HideLevel(const FName& level) const | |
{ | |
auto levelstream = UGameplayStatics::GetStreamingLevel( GetWorld(), level ); | |
check(levelstream != nullptr); | |
levelstream->SetShouldBeVisible( false ); | |
return !levelstream->IsLevelVisible(); | |
} | |
// ロード/アンロードの完了確認 | |
bool ALevelControl::IsCompleted() const | |
{ | |
return Complete; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment