Documentation for the Unreal C++ Plugin
Loading...
Searching...
No Matches
GameManager.cpp
Go to the documentation of this file.
1// Fill out your copyright notice in the Description page of Project Settings.
2
4
8#include "GameFramework/GameModeBase.h"
10#include "Kismet/GameplayStatics.h"
12
21
23{
24 InteractiveItemsArray.Add(InteractableActor);
25 OnInteractiveItemAdded(InteractableActor);
26 OnNewInteractableItemAdded.Broadcast(InteractableActor);
27 if (InteractableActor->IsAutoStepDataPopulationActive && (InteractiveObjectStepDataBase.Num() != 0))
29}
30
32{
34 {
36 {
37 InitializeNewDynamicStory(DynamicStoryData);
38 }
39 else
40 {
41 DynamicStoryQueue.Add(DynamicStoryData);
42 }
43 }
44}
45
47{
48 if (ScriptInstancesData.Num())
49 ScriptInstancesData.Empty();
50
52 {
53 return;
54 }
55 for (auto StoryScript : StoryScriptClassData->ScriptData)
56 {
57 UStoryScript* TempScript = NewObject<UStoryScript>(this, StoryScript.StepScriptClass);
58 ScriptInstancesData.Add(FScriptInstanceData(StoryScript.StepName, TempScript));
59 TempScript->ScriptInitialization();
60 }
61}
62
79
96
97void UGameManager::GetAllActorsOfClass(TSubclassOf<AActor> TargetClass, TArray<AActor*>& OutActors)
98{
99 if (UWorld* World = GetWorld())
100 {
101 UGameplayStatics::GetAllActorsOfClass(World, TargetClass, OutActors);
102 }
103}
104
105void UGameManager::OnInitialization_Implementation()
106{
107}
108
110{
111 if (TargetActor && TargetActor->Story && !TargetActor->ActiveStepsAcquiredFromParent)
112 {
113 TargetActor->Story->ActiveSteps.Empty();
114 TargetActor->HighlightComponent->HighlightActiveOnSteps.Empty();
115 for (auto const InteractableObjectDataBase : InteractiveObjectStepDataBase)
116 {
117 for (auto const & InteractableObjectData : InteractableObjectDataBase->InteractiveObjectData)
118 {
119 if (TargetActor->IsA(InteractableObjectData.InteractiveObject))
120 {
121 TargetActor->Story->ActiveSteps.Append(InteractableObjectData.StorySteps);
122 TargetActor->HighlightComponent->HighlightActiveOnSteps.Append(InteractableObjectData.HighlightSteps);
123 // Populate with step data child actors
124 if (TargetActor->ChildClassesThatAcquiredPopulatedData.Num())
125 {
126 TArray<AActor*> ChildActorsArray;
127 TargetActor->GetAllChildActors(ChildActorsArray);
128 for (auto const ChildActor : ChildActorsArray)
129 {
130 Cast<ABaseStoryActor>(ChildActor)->Story->ActiveSteps.Empty();
131 Cast<ABaseStoryActor>(ChildActor)->HighlightComponent->HighlightActiveOnSteps.Empty();
132 for (auto ChildClass : TargetActor->ChildClassesThatAcquiredPopulatedData)
133 {
134 if (ChildActor->IsA(ChildClass))
135 {
136 Cast<ABaseStoryActor>(ChildActor)->ActiveStepsAcquiredFromParent = true;
137 Cast<ABaseStoryActor>(ChildActor)->Story->ActiveSteps.Append(InteractableObjectData.StorySteps);
138 Cast<ABaseStoryActor>(ChildActor)->HighlightComponent->HighlightActiveOnSteps.Append(InteractableObjectData.HighlightSteps);
139 }
140 }
141 }
142 }
143 break;
144 }
145 }
146 }
147 }
148}
149
150void UGameManager::OnGrabbingWrongActor_Implementation(AActor* WrongActor)
151{
152}
153
154void UGameManager::OnTeleportActivatedRaw_Implementation(EControllerHand Hand, bool InActivate)
155{
156}
157
159{
162}
163
165{
168}
169
171{
172 GameModeBaseRef = GetWorld()->GetAuthGameMode();
173 if (GameModeBaseRef->GetClass()->ImplementsInterface(UPixoCoreInterface::StaticClass()))
174 {
175 SoundManagerRef = Cast<USoundManager>(IPixoCoreInterface::Execute_GetManagerRef(GameModeBaseRef, USoundManager::StaticClass()));
176 if (!SoundManagerRef)
177 {
178 UE_LOG(LogTemp, Error, TEXT("Sound Manager has not been setup for this project!"));
179 }
180
181 StoryManagerRef = Cast<UStoryManager>(IPixoCoreInterface::Execute_GetManagerRef(GameModeBaseRef, UStoryManager::StaticClass()));
182 if (StoryManagerRef)
183 {
185 }
186 }
187 else
188 UE_LOG(LogTemp, Error, TEXT("Game mode doesn't implement PixoCore Interface"));
189
190 PlayerPawnRef = Cast<APixoVRCharacter>(GetWorld()->GetFirstPlayerController()->GetPawn());
191 if (PlayerPawnRef)
192 {
194 }
195 else
196 UE_LOG(LogTemp, Error, TEXT("PlayerPawn reference is invalid!"));
197
199 {
201 }
202
204}
#define DEFINE_EVENT_HANDLER(TEventType)
Definition BaseManager.h:13
Base class for story actors.
UStoryComponent * Story
UPROPERTY(BlueprintReadWrite, EditAnywhere)
bool ActiveStepsAcquiredFromParent
bool IsAutoStepDataPopulationActive
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "BaseStoryActor|DynamicStory")
TArray< TSubclassOf< ABaseStoryActor > > ChildClassesThatAcquiredPopulatedData
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "BaseStoryActor|DynamicStory",...
UHighlightComponent * HighlightComponent
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FOnTeleportationActivated & OnTeleportationActivated()
void HandleEvent_Impl(class UBaseEvent *Event)
FText CurrentStep
UPROPERTY(BlueprintReadWrite, Category = "GameManager")
FOnNewInteractableItemAdded OnNewInteractableItemAdded
UPROPERTY(BlueprintAssignable, Category = "GameManager|Delegates")
void OnInitialization()
Function for overriding. Called when initialization ended.
void OnTeleportActivatedRaw(EControllerHand Hand, bool InActivate)
Function for overriding. Called when teleportation is activated.
FOnWrongInteractableActorGrabbed OnWrongInteractableActorGrabbed
UPROPERTY(BlueprintReadWrite, BlueprintCallable, BlueprintAssignable)
void SpawnStoryScripts()
UFUNCTION()
TArray< UStoryScriptClassData * > DynamicStoryScripts
UPROPERTY()
void NewDynamicStoryAdded(FDynamicStoryData DynamicStoryData)
UFUNCTION(BlueprintCallable, Category = "GameManager|DynamicStory")
void OnInteractiveItemAdded(ABaseStoryActor *AddedInteractiveItem)
Function for overriding. Called when the interactive item is added to InteractiveItemsArray.
AGameModeBase * GameModeBaseRef
UPROPERTY(BlueprintReadWrite, Category = "GameManager")
void OnNewStepLoaded(const FText &StepName)
Function for overriding. Called when a new step is loaded.
void OnEndStoryReached()
UFUNCTION()
void GetAllActorsOfClass(TSubclassOf< AActor > TargetClass, TArray< AActor * > &OutActors)
UFUNCTION(BlueprintCallable, Category = "GameManager|Functionality")
TArray< UInteractiveObjectDataBase * > InteractiveObjectStepDataBase
UPROPERTY()
TArray< FDynamicStoryData > DynamicStoryQueue
UPROPERTY()
void AddNewInteractableObject(ABaseStoryActor *InteractableActor)
UFUNCTION(BlueprintCallable, Category = "GameManager|InteractiveItems")
TArray< FScriptInstanceData > ScriptInstancesData
UPROPERTY(BlueprintReadOnly, Category = "GamaManager|Script")
APixoVRCharacter * PlayerPawnRef
UPROPERTY(BlueprintReadWrite, Category = "GameManager")
UStoryManager * StoryManagerRef
UPROPERTY(BlueprintReadWrite, Category = "GameManager")
void PopulateInteractiveObjectsWithStepData(ABaseStoryActor *TargetActor)
UFUNCTION(BlueprintCallable, Category = "GameManager|InteractiveItems")
TArray< ABaseStoryActor * > InteractiveItemsArray
UPROPERTY(BlueprintReadOnly, Category = "GameManager|InteractiveItems")
UStoryScriptClassData * StoryScriptClassData
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GameManager|Script")
bool IsUsingStoryScriptData
UPROPERTY(EditDefaultsOnly, Category = "GameManager|Script")
USoundManager * SoundManagerRef
UPROPERTY(BlueprintReadWrite, Category = "GameManager")
void InitializeNewDynamicStory(FDynamicStoryData DynamicStoryData)
UFUNCTION()
void OnNewStoryLoaded(const FText &StepName)
Function for overriding. Called when a new story is loaded.
int ActiveDynamicStoryIndex
UPROPERTY()
void OnGrabbingWrongActor(AActor *WrongActor)
Function for overriding. Called when the wrong interactable actor is grabbed.
TArray< FText > HighlightActiveOnSteps
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Highlight")
Event called when we on init experience.
Event called when new step is loaded.
Event called when new story is loaded.
FStoryStep CurrentStep
TArray< FText > ActiveSteps
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Story|Setup")
bool IsAutoSwitchingToNextStoryActive
UPROPERTY(EditInstanceOnly, Category = "StoryManager|Properties")
bool InitNewStory(int newStoryIndex)
Choose one story from StoryDataArray.
TArray< UStoryData * > StoryDataArray
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool StoryFinished
UPROPERTY(BlueprintReadOnly)
FOnEndOfStory OnEndOfStory
UPROPERTY(BlueprintAssignable, Category = "Story Delegate")
TArray< FScriptClassData > ScriptData
UPROPERTY(EditAnywhere)
Definition StoryScript.h:91
UCLASS(BlueprintType, Blueprintable, meta = (ShowWorldContexPin))
void ScriptInitialization()
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Script")
USTRUCT(BlueprintType)
TArray< UStoryData * > DynamicStoryData
UPROPERTY(BlueprintReadWrite)
TArray< UStoryScriptClassData * > StoryScripts
UPROPERTY(BlueprintReadWrite)
TArray< UInteractiveObjectDataBase * > InteractiveObjectData
UPROPERTY(BlueprintReadWrite)
Struct for holding script instance data.
Definition StoryScript.h:47
FText StepName
UPROPERTY(BlueprintReadWrite, EditAnywhere)