Create LevelKeyPickup
This commit is contained in:
parent
a183445aba
commit
532bcc7e66
|
@ -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);
|
||||
}
|
|
@ -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;
|
||||
};
|
|
@ -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)
|
||||
|
|
|
@ -26,3 +26,13 @@ void UNakatomiLevelManager::LoadNextLevel()
|
|||
UGameplayStatics::OpenLevelBySoftObjectPtr(GetWorld(), NextLevel);
|
||||
}
|
||||
}
|
||||
|
||||
void UNakatomiLevelManager::IncrementInitialLevelKeys()
|
||||
{
|
||||
LevelKeys++;
|
||||
}
|
||||
|
||||
void UNakatomiLevelManager::IncrementCollectedLevelKeys()
|
||||
{
|
||||
CollectedLevelKeys++;
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue