A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
SoundManager.cpp
Go to the documentation of this file.
1// Copyright(c) Pixo Group. All Rights Reserved.
2
4#include "Components/AudioComponent.h"
10
22
23USoundCue* USoundManager::GetSoundBasedOnStep(FText stepName, UDataTable* DataTable)
24{
25 static const FString ContextString(TEXT("Sound"));
26 if (DataTable)
27 {
28 TArray<FName> rowNames = DataTable->GetRowNames();
29 if (rowNames.Num() == 0)
30 {
31 UE_LOG(LogTemp, Error, TEXT("Voice over DataTable is empty!"))
32 return nullptr;
33 }
34 for (const auto rowName : rowNames)
35 {
36 FStepVO* findedSound = DataTable->FindRow<FStepVO>(rowName, ContextString);
37 if (findedSound->StepName.EqualTo(stepName))
38 {
39 return findedSound->SoundCue;
40 }
41 }
42 }
43 else
44 UE_LOG(LogTemp, Error, TEXT("Voice over DataTable is invalid!"));
45 return nullptr;
46}
47
48void USoundManager::PlaySound(USoundCue* soundToPlay)
49{
50 if (soundToPlay)
51 {
52 AudioComponent->SetSound(soundToPlay);
53 AudioComponent->Play();
54 }
55}
56
61
63{
64 OnVoEndPlaying.Broadcast();
65}
66
68{
69 GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, "UPlaySoundEvent");
70 PlaySound(Event->MySoundCue);
71}
72
74{
75 CurrentStep = Event->CurrentStep.StepName;
77}
78
80{
81 CurrentStep = Event->CurrentStep.StepName;
83}
84
86{
88 {
90 }
91}
92
94{
95 const int32 StoryIndex = UStoryManager::GetNextStoryIndex();
96 TArray<FText> StoryParameters = UStoryManager::GetStoryParameters();
97
98 if (StoryParameters.Num() != 0 && SoundManagerParametersData)
99 {
100 for (auto StoryParameter : StoryParameters)
101 {
102 for (auto SoundManagerParameter : SoundManagerParametersData->Data)
103 {
104 if (StoryParameter.EqualTo(SoundManagerParameter.ParameterName) && StoryIndex == SoundManagerParameter.StoryIndex)
105 {
106 CurrentStepVODataTable = SoundManagerParameter.DependentSoundTable;
107 return;
108 }
109 }
110 }
111 }
112
113 if (StepVODataTablesArray.Num() != 0)
114 {
115 if (StepVODataTablesArray.IsValidIndex(StoryIndex))
116 {
118 }
119 else if (StepVODataTablesArray[0])
120 {
122 UE_LOG(LogTemp, Warning, TEXT("SoundManager - StepVODataTablesArray didn't have StoryIndex value, zero array element is selected"));
123 }
124 else
125 UE_LOG(LogTemp, Error, TEXT("SoundManager - CurrentStepVODataTable wasn't set up"));
126 }
127 else
128 UE_LOG(LogTemp, Error, TEXT("SoundManager - StepVODataTablesArray is empty!"));
129
130 if (StepHintVODataTablesArray.Num() != 0)
131 {
132 if (StepHintVODataTablesArray.IsValidIndex(StoryIndex))
133 {
135 }
136 else if (StepHintVODataTablesArray[0])
137 {
139 UE_LOG(LogTemp, Warning, TEXT("SoundManager - StepVODataTablesArray didn't have StoryIndex value, zero array element is selected"));
140 }
141 else
142 UE_LOG(LogTemp, Error, TEXT("SoundManager - CurrentStepHintVODataTable wasn't set up"));
143 }
144 else
145 UE_LOG(LogTemp, Warning, TEXT("SoundManager - StepHintVODataTablesArray is empty!"));
146}
#define DEFINE_EVENT_HANDLER(TEventType)
Definition BaseManager.h:13
void HandleEvent_Impl(class UBaseEvent *Event)
Event used to call when hint activated or deactivated.
Event called when we on init experience.
Event called when new step is loaded.
Event called when new story is loaded.
Event used to call to play sound.
void OnStepChange(FText stepName)
Play sound based on the new step.
void PlaySound(USoundCue *soundToPlay)
UFUNCTION(BlueprintCallable)
TArray< UDataTable * > StepVODataTablesArray
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Components")
USoundCue * GetSoundBasedOnStep(FText stepName, UDataTable *DataTable)
Retrieves a sound cue based on the step name.
FOnVOEndPlaying OnVoEndPlaying
UPROPERTY(BlueprintAssignable)
UAudioComponent * AudioComponent
UPROPERTY(BlueprintReadWrite, Category = "Components")
UDataTable * CurrentStepHintVODataTable
UPROPERTY(BlueprintReadWrite, Category = "Components")
TArray< UDataTable * > StepHintVODataTablesArray
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Components")
USoundManagerParametersData * SoundManagerParametersData
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "SoundManager")
void OnAudioEndPlaying()
Called when audio playback ends.
UDataTable * CurrentStepVODataTable
UPROPERTY(BlueprintReadWrite, Category = "Components")
static int GetNextStoryIndex()
UFUNCTION(BlueprintCallable)
static TArray< FText > GetStoryParameters()
UFUNCTION(BlueprintCallable)
Represents a Step Value Object used for storing step data in a data table.
USoundCue * SoundCue
UPROPERTY(EditAnywhere, BlueprintReadOnly)
FText StepName
UPROPERTY(EditAnywhere, BlueprintReadOnly)