Compare commits

..

2 Commits

Author SHA1 Message Date
baz 532bcc7e66 Create LevelKeyPickup 2024-03-11 21:01:50 +00:00
baz a183445aba Create LevelManager 2024-03-11 20:01:56 +00:00
7 changed files with 163 additions and 4 deletions

View File

@ -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();

View File

@ -0,0 +1,33 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "LevelKeyPickup.h"
#include "NakatomiGameInstance.h"
#include "Kismet/GameplayStatics.h"
void ALevelKeyPickup::BeginPlay()
{
Super::BeginPlay();
if (auto gameInstance = Cast<UNakatomiGameInstance>(UGameplayStatics::GetGameInstance(GetWorld())))
{
gameInstance->GetCurrentLevelManager()->IncrementInitialLevelKeys();
}
}
void ALevelKeyPickup::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void ALevelKeyPickup::OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if (auto gameInstance = Cast<UNakatomiGameInstance>(UGameplayStatics::GetGameInstance(GetWorld())))
{
gameInstance->GetCurrentLevelManager()->IncrementInitialLevelKeys();
}
Super::OnOverlapBegin(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
}

View File

@ -0,0 +1,25 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Pickup.h"
#include "LevelKeyPickup.generated.h"
/**
*
*/
UCLASS()
class NAKATOMI_API ALevelKeyPickup : public APickup
{
GENERATED_BODY()
protected:
virtual void BeginPlay() override;
public:
virtual void Tick(float DeltaTime) override;
virtual void OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) override;
};

View File

@ -7,3 +7,15 @@ 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()
{
return IsValid(currentLevelManager)
? currentLevelManager
: currentLevelManager = NewObject<UNakatomiLevelManager>(this, TEXT("Level Manager"));
}
void UNakatomiGameInstance::SetCurrentLevelManager(UNakatomiLevelManager* NewLevelManager)
{
currentLevelManager = NewLevelManager;
}

View File

@ -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);
}; };

View File

@ -0,0 +1,38 @@
// 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);
}
}
void UNakatomiLevelManager::IncrementInitialLevelKeys()
{
LevelKeys++;
}
void UNakatomiLevelManager::IncrementCollectedLevelKeys()
{
CollectedLevelKeys++;
}

View File

@ -0,0 +1,40 @@
// 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;
int LevelKeys = 0;
int CollectedLevelKeys = 0;
public:
UFUNCTION()
void LoadNextLevel();
UFUNCTION()
void IncrementInitialLevelKeys();
UFUNCTION()
void IncrementCollectedLevelKeys();
private:
UFUNCTION()
void BeginPlay(UWorld* world);
};