Documentation for the Unreal C++ Plugin
Loading...
Searching...
No Matches
StoryComponent.cpp
Go to the documentation of this file.
1// Copyright(c) Pixo Group. All Rights Reserved.
2
4#include "GameFramework/GameModeBase.h"
8
10{
11 Super::BeginPlay();
12
13 if(GetOwner()->GetClass()->ImplementsInterface(UPixoVRStoryObject::StaticClass()))
14 {
15 if(GetWorld()->GetAuthGameMode()->GetClass()->ImplementsInterface(UPixoCoreInterface::StaticClass()))
16 {
17 const auto GameMode = GetWorld()->GetAuthGameMode();
18 GameManager = Cast<UGameManager>(IPixoCoreInterface::Execute_GetManagerRef(GameMode, UGameManager::StaticClass()));
19 //refactor this !!!
20 ABaseStoryActor* OwnerRef = Cast<ABaseStoryActor>(GetOwner());
21 if (GameManager && OwnerRef)
22 {
24 }
25 StoryManager = Cast<UStoryManager>(IPixoCoreInterface::Execute_GetManagerRef(GameMode, UStoryManager::StaticClass()));
26 if (StoryManager)
27 {
31
33 }
34 }
35 else
36 {
37 GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "Error - GameMode doesn't implement UPixoCoreInterface!");
38 }
39 }
40 else
41 {
42 const FString ErrorMassage = "WARNING___Actor__" + GetOwner()->GetName() + "__Has_Not_Implemented_BI_InteractableObjectInterface";
43 GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, ErrorMassage);
44 }
45}
46
48{
50 {
52 {
53 FText StepName = StoryManager->CurrentStep.StepName;
54 for (auto ScriptInstance : GameManager->ScriptInstancesData)
55 {
56 if (ScriptInstance.StepName.EqualTo(StepName))
57 {
58 ScriptInstance.StepScriptInstance->ExecuteScript(GetOwner());
59 }
60 }
61 }
62 }
63 else
64 UE_LOG(LogTemp, Error, TEXT("Error - StoryComponent - GameManager, Story Manager is not valid!"));
65}
66
67void UStoryComponent::NewStep(FStoryStep NewStep, bool IsForward)
68{
71
72 bool StepFound = false;
73 bool SubStepFound = false;
74 for(auto Step : ActiveSteps)
75 {
76 if(ActiveStep.EqualTo(Step))
77 {
78 StepFound = true;
79 break;
80 }
81 }
82 for(auto SubStep : ActiveSubSteps)
83 {
84 if (ActiveSubStep.EqualTo(SubStep))
85 {
86 SubStepFound = true;
87 break;
88 }
89 }
90 if(GetOwner()->GetClass()->ImplementsInterface(UPixoVRStoryObject::StaticClass()))
91 {
92 if(StepFound && (SubStepFound || ActiveSubSteps.Num() == 0 || ActiveSubStep.IsEmpty()))
93 {
96 ObjectActive = true;
97 IPixoVRStoryObject::Execute_ObjectActivated(GetOwner());
98 }
99 else
100 {
101 ObjectActive = false;
102 IPixoVRStoryObject::Execute_ObjectDeactivated(GetOwner());
103 }
104 }
105 else
106 {
107 GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "PixoVRInteractiveObject interface not implemented!!!");
108 }
109}
110
112{
114 ActiveSubStep = NewSubStep.StepName;
115
116 bool StepFound = false;
117 bool SubStepFound = false;
118 for(auto Step : ActiveSteps)
119 {
120 if(ActiveStep.EqualTo(Step))
121 {
122 StepFound = true;
123 break;
124 }
125 }
126 for(auto SubStep : ActiveSubSteps)
127 {
128 if (ActiveSubStep.EqualTo(SubStep))
129 {
130 SubStepFound = true;
131 break;
132 }
133 }
134 if(GetOwner()->GetClass()->ImplementsInterface(UPixoVRStoryObject::StaticClass()))
135 {
136 if (StepFound && (SubStepFound || ActiveSubSteps.Num() == 0))
137 {
140 ObjectActive = true;
141 IPixoVRStoryObject::Execute_ObjectActivated(GetOwner());
142 }
143 else
144 {
145 ObjectActive = false;
146 IPixoVRStoryObject::Execute_ObjectDeactivated(GetOwner());
147 }
148 }
149 else
150 {
151 GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "PixoVRInteractiveObject interface not implemented!!!");
152 }
153}
154
Base class for story actors.
void AddNewInteractableObject(ABaseStoryActor *InteractableActor)
UFUNCTION(BlueprintCallable, Category = "GameManager|InteractiveItems")
TArray< FScriptInstanceData > ScriptInstancesData
UPROPERTY(BlueprintReadOnly, Category = "GamaManager|Script")
bool IsUsingStoryScriptData
UPROPERTY(EditDefaultsOnly, Category = "GameManager|Script")
FText ActiveStep
UPROPERTY(BlueprintReadWrite)
virtual void BeginPlay() override
TArray< FText > ActiveSteps
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Story|Setup")
UGameManager * GameManager
UPROPERTY(BlueprintReadOnly, Category = "Story|Setup")
void NewStep(FStoryStep NewStep, bool IsForward)
Called when a new step is reached in the story.
bool ObjectActive
UPROPERTY(BlueprintReadWrite)
FText ActiveSubStep
UPROPERTY(BlueprintReadWrite)
void StoryLoaded()
Called when the story is loaded.
void ExecuteScript()
UFUNCTION(BlueprintCallable, Category = "Story|Script")
void NewSubStep(FStoryStep NewSubStep)
Called when a new substep is reached in the story.
TArray< FText > ActiveSubSteps
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Story|Setup")
UStoryManager * StoryManager
UPROPERTY(BlueprintReadWrite)
FOnNewStep OnNewStep
UPROPERTY(BlueprintAssignable, Category = "Story Delegate")
FStoryStep CurrentSubStep
UPROPERTY(BlueprintReadWrite, Replicated)
FOnStoryLoaded OnStoryLoaded
UPROPERTY(BlueprintAssignable, Category = "Story Delegate")
FOnNewSubStep OnNewSubStep
UPROPERTY(BlueprintAssignable, Category = "Story Delegate")
FStoryStep CurrentStep
UPROPERTY(BlueprintReadWrite, Replicated)
USTRUCT(BlueprintType)
FText StepName
UPROPERTY(BlueprintReadWrite, EditAnywhere)