Create LevelManager
This commit is contained in:
parent
29246357dc
commit
a183445aba
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include <Kismet/GameplayStatics.h>
|
#include <Kismet/GameplayStatics.h>
|
||||||
|
|
||||||
|
#include "NakatomiGameInstance.h"
|
||||||
#include "PlayerCharacter.h"
|
#include "PlayerCharacter.h"
|
||||||
|
|
||||||
void ALevelEndTriggerVolume::BeginPlay()
|
void ALevelEndTriggerVolume::BeginPlay()
|
||||||
|
@ -28,9 +29,9 @@ void ALevelEndTriggerVolume::OnOverlapBegin(UPrimitiveComponent* OverlappedCompo
|
||||||
{
|
{
|
||||||
GetCollisionComponent()->OnComponentBeginOverlap.Clear();
|
GetCollisionComponent()->OnComponentBeginOverlap.Clear();
|
||||||
|
|
||||||
if (!NextGameLevel.IsNull())
|
if (auto gameInstance = Cast<UNakatomiGameInstance>(UGameplayStatics::GetGameInstance(GetWorld())))
|
||||||
{
|
{
|
||||||
UGameplayStatics::OpenLevelBySoftObjectPtr(GetWorld(), NextGameLevel);
|
gameInstance->GetCurrentLevelManager()->LoadNextLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
this->Destroy();
|
this->Destroy();
|
||||||
|
|
|
@ -7,3 +7,20 @@ UNakatomiAIAttackTokenManager* UNakatomiGameInstance::GetAIAttackTokenManager()
|
||||||
{
|
{
|
||||||
return IsValid(AIAttackTokenManager) ? AIAttackTokenManager : (AIAttackTokenManager = NewObject<UNakatomiAIAttackTokenManager>(this, TEXT("AI Attack Token Manager")));
|
return IsValid(AIAttackTokenManager) ? AIAttackTokenManager : (AIAttackTokenManager = NewObject<UNakatomiAIAttackTokenManager>(this, TEXT("AI Attack Token Manager")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UNakatomiLevelManager* UNakatomiGameInstance::GetCurrentLevelManager()
|
||||||
|
{
|
||||||
|
if (IsValid(currentLevelManager))
|
||||||
|
{
|
||||||
|
return currentLevelManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
UE_LOG(LogTemp, Warning, TEXT("No Level manager set."))
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UNakatomiGameInstance::SetCurrentLevelManager(UNakatomiLevelManager* NewLevelManager)
|
||||||
|
{
|
||||||
|
currentLevelManager = NewLevelManager;
|
||||||
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
#include "Engine/GameInstance.h"
|
#include "Engine/GameInstance.h"
|
||||||
#include "NakatomiAIAttackTokenManager.h"
|
#include "NakatomiAIAttackTokenManager.h"
|
||||||
|
#include "NakatomiLevelManager.h"
|
||||||
#include "NakatomiGameInstance.generated.h"
|
#include "NakatomiGameInstance.generated.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,6 +16,10 @@ class NAKATOMI_API UNakatomiGameInstance : public UGameInstance
|
||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
UNakatomiLevelManager* currentLevelManager;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
|
@ -25,4 +30,9 @@ public:
|
||||||
UFUNCTION(BlueprintCallable)
|
UFUNCTION(BlueprintCallable)
|
||||||
UNakatomiAIAttackTokenManager* GetAIAttackTokenManager();
|
UNakatomiAIAttackTokenManager* GetAIAttackTokenManager();
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable)
|
||||||
|
UNakatomiLevelManager* GetCurrentLevelManager();
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable)
|
||||||
|
void SetCurrentLevelManager(UNakatomiLevelManager* NewLevelManager);
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "NakatomiLevelManager.h"
|
||||||
|
|
||||||
|
#include "NakatomiGameInstance.h"
|
||||||
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
|
||||||
|
UNakatomiLevelManager::UNakatomiLevelManager()
|
||||||
|
{
|
||||||
|
FWorldDelegates::OnPostWorldCreation.AddUObject(this, &UNakatomiLevelManager::BeginPlay);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UNakatomiLevelManager::BeginPlay(UWorld* world)
|
||||||
|
{
|
||||||
|
if (auto gameInstance = Cast<UNakatomiGameInstance>(UGameplayStatics::GetGameInstance(GetWorld())))
|
||||||
|
{
|
||||||
|
gameInstance->SetCurrentLevelManager(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UNakatomiLevelManager::LoadNextLevel()
|
||||||
|
{
|
||||||
|
if (!NextLevel.IsNull())
|
||||||
|
{
|
||||||
|
UGameplayStatics::OpenLevelBySoftObjectPtr(GetWorld(), NextLevel);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "NakatomiLevelManager.generated.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
UCLASS()
|
||||||
|
class NAKATOMI_API UNakatomiLevelManager : public UObject
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
UNakatomiLevelManager();
|
||||||
|
|
||||||
|
private:
|
||||||
|
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
|
||||||
|
TSoftObjectPtr<UWorld> NextLevel;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void LoadNextLevel();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void BeginPlay(UWorld* world);
|
||||||
|
};
|
Loading…
Reference in New Issue