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()
|
UNakatomiLevelManager* UNakatomiGameInstance::GetCurrentLevelManager()
|
||||||
{
|
{
|
||||||
if (IsValid(currentLevelManager))
|
return IsValid(currentLevelManager)
|
||||||
{
|
? currentLevelManager
|
||||||
return currentLevelManager;
|
: currentLevelManager = NewObject<UNakatomiLevelManager>(this, TEXT("Level Manager"));
|
||||||
}
|
|
||||||
|
|
||||||
UE_LOG(LogTemp, Warning, TEXT("No Level manager set."))
|
|
||||||
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UNakatomiGameInstance::SetCurrentLevelManager(UNakatomiLevelManager* NewLevelManager)
|
void UNakatomiGameInstance::SetCurrentLevelManager(UNakatomiLevelManager* NewLevelManager)
|
||||||
|
|
|
@ -26,3 +26,13 @@ void UNakatomiLevelManager::LoadNextLevel()
|
||||||
UGameplayStatics::OpenLevelBySoftObjectPtr(GetWorld(), NextLevel);
|
UGameplayStatics::OpenLevelBySoftObjectPtr(GetWorld(), NextLevel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UNakatomiLevelManager::IncrementInitialLevelKeys()
|
||||||
|
{
|
||||||
|
LevelKeys++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UNakatomiLevelManager::IncrementCollectedLevelKeys()
|
||||||
|
{
|
||||||
|
CollectedLevelKeys++;
|
||||||
|
}
|
||||||
|
|
|
@ -19,11 +19,20 @@ private:
|
||||||
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
|
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
|
||||||
TSoftObjectPtr<UWorld> NextLevel;
|
TSoftObjectPtr<UWorld> NextLevel;
|
||||||
|
|
||||||
public:
|
int LevelKeys = 0;
|
||||||
|
|
||||||
|
int CollectedLevelKeys = 0;
|
||||||
|
|
||||||
|
public:
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void LoadNextLevel();
|
void LoadNextLevel();
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void IncrementInitialLevelKeys();
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void IncrementCollectedLevelKeys();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
|
|
Loading…
Reference in New Issue