-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSaveGameTriggerSphere.cpp
More file actions
68 lines (55 loc) · 1.8 KB
/
Copy pathSaveGameTriggerSphere.cpp
File metadata and controls
68 lines (55 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "SaveGameTriggerSphere.h"
#include "Components/SphereComponent.h"
#include "Components/TextRenderComponent.h"
#include "SaveGameSubsystem.h"
// Sets default values
ASaveGameTriggerSphere::ASaveGameTriggerSphere()
{
PrimaryActorTick.bCanEverTick = false;
Root = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
#if WITH_EDITORONLY_DATA
Root->bVisualizeComponent = true;
#endif
RootComponent = Root;
Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
Mesh->SetupAttachment(RootComponent);
Text = CreateDefaultSubobject<UTextRenderComponent>(TEXT("Text"));
Text->SetHorizontalAlignment(EHorizTextAligment::EHTA_Center);
Text->SetupAttachment(RootComponent);
Sphere = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere"));
Sphere->SetHiddenInGame(false);
Sphere->SetupAttachment(RootComponent);
Sphere->OnComponentBeginOverlap.AddDynamic(this, &ASaveGameTriggerSphere::OnBeginOverlap);
}
void ASaveGameTriggerSphere::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if (OtherActor != nullptr && OtherActor != this)
{
if (bLoadGame)
{
LoadGame();
return;
}
if (bSaveGame)
{
SaveGame();
return;
}
if (bResetData) ResetData();
}
}
void ASaveGameTriggerSphere::LoadGame()
{
USaveGameSubsystem* SaveSubsystem = GetGameInstance()->GetSubsystem<USaveGameSubsystem>();
SaveSubsystem->LoadGame();
}
void ASaveGameTriggerSphere::ResetData()
{
USaveGameSubsystem* SaveSubsystem = GetGameInstance()->GetSubsystem<USaveGameSubsystem>();
SaveSubsystem->ResetData();
}
void ASaveGameTriggerSphere::SaveGame()
{
USaveGameSubsystem* SaveSubsystem = GetGameInstance()->GetSubsystem<USaveGameSubsystem>();
SaveSubsystem->SaveGame();
}