Create LevelKeyPickup

This commit is contained in:
baz 2024-03-11 21:01:50 +00:00
parent a183445aba
commit 532bcc7e66
5 changed files with 81 additions and 9 deletions

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

@ -10,14 +10,9 @@ UNakatomiAIAttackTokenManager* UNakatomiGameInstance::GetAIAttackTokenManager()
UNakatomiLevelManager* UNakatomiGameInstance::GetCurrentLevelManager()
{
if (IsValid(currentLevelManager))
{
return currentLevelManager;
}
UE_LOG(LogTemp, Warning, TEXT("No Level manager set."))
return nullptr;
return IsValid(currentLevelManager)
? currentLevelManager
: currentLevelManager = NewObject<UNakatomiLevelManager>(this, TEXT("Level Manager"));
}
void UNakatomiGameInstance::SetCurrentLevelManager(UNakatomiLevelManager* NewLevelManager)

View File

@ -26,3 +26,13 @@ void UNakatomiLevelManager::LoadNextLevel()
UGameplayStatics::OpenLevelBySoftObjectPtr(GetWorld(), NextLevel);
}
}
void UNakatomiLevelManager::IncrementInitialLevelKeys()
{
LevelKeys++;
}
void UNakatomiLevelManager::IncrementCollectedLevelKeys()
{
CollectedLevelKeys++;
}

View File

@ -19,11 +19,20 @@ private:
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
TSoftObjectPtr<UWorld> NextLevel;
public:
int LevelKeys = 0;
int CollectedLevelKeys = 0;
public:
UFUNCTION()
void LoadNextLevel();
UFUNCTION()
void IncrementInitialLevelKeys();
UFUNCTION()
void IncrementCollectedLevelKeys();
private:
UFUNCTION()