Documentation for the Unreal C++ Plugin
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#include "Kismet/GameplayStatics.h"
11
23
24USoundCue* USoundManager::GetSoundBasedOnStep(FText stepName, UDataTable* DataTable)
25{
26 static const FString ContextString(TEXT("Sound"));
27 if (DataTable)
28 {
29 TArray<FName> rowNames = DataTable->GetRowNames();
30 if (rowNames.Num() == 0)
31 {
32 UE_LOG(LogTemp, Error, TEXT("Voice over DataTable is empty!"))
33 return nullptr;
34 }
35 for (const auto rowName : rowNames)
36 {
37 FStepVO* findedSound = DataTable->FindRow<FStepVO>(rowName, ContextString);
38 if (findedSound->StepName.EqualTo(stepName))
39 {
40 return findedSound->SoundCue;
41 }
42 }
43 }
44 else
45 UE_LOG(LogTemp, Error, TEXT("Voice over DataTable is invalid!"));
46 return nullptr;
47}
48
49void USoundManager::PlaySound(USoundCue* soundToPlay)
50{
51 if (soundToPlay)
52 {
53 AudioComponent->SetSound(soundToPlay);
54 AudioComponent->Play();
55 }
56}
57
59 USoundBase* soundToPlay,
60 float volumeMultiplier,
61 float pitchMultiplier,
62 float startTime,
63 USoundConcurrency* concurrencySettings,
64 AActor* owningActor,
65 bool bIsUISound)
66{
67 if (soundToPlay)
68 {
69 UGameplayStatics::PlaySound2D(
70 GetWorld(),
71 soundToPlay,
72 volumeMultiplier,
73 pitchMultiplier,
74 startTime,
75 concurrencySettings,
76 owningActor,
77 bIsUISound);
78 UE_LOG(LogTemp, Log, TEXT("USoundManager::PlayBackgroundSound: Playing - %s"), *soundToPlay->GetName());
79 }
80}
81
82void USoundManager::PlaySFXSound(USoundBase* soundToPlay)
83{
84 if (soundToPlay)
85 {
86 UGameplayStatics::PlaySound2D(GetWorld(), soundToPlay, SFXVolumeMultiplier);
87 UE_LOG(LogTemp, Log, TEXT("USoundManager::PlaySFXSound: Playing - %s"), *soundToPlay->GetName());
88 }
89}
90
95
97{
98 OnVoEndPlaying.Broadcast();
99}
100
102{
103 GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, "UPlaySoundEvent");
104 PlaySound(Event->MySoundCue);
105}
106
108{
111}
112
114{
117}
118
120{
122 {
124 }
125}
126
128{
130
131 const int32 StoryIndex = UStoryManager::GetNextStoryIndex();
132
134 {
135 for (FBackgroundSound BackgroundSound : BackgroundSounds)
136 {
137 if (BackgroundSound.Sound && (!BackgroundSound.AppropriateStoryParams.Num() || UStoryManager::IsSpecificParametersExist(BackgroundSound.AppropriateStoryParams)))
138 PlayBackgroundSound(BackgroundSound.Sound, BackgroundVolumeMultiplier);
139 }
140 }
141
143 {
144 for (auto SoundManagerParameter : SoundManagerParametersData->Data)
145 {
146 if (UStoryManager::IsSpecificParametersExist(SoundManagerParameter.ParametersName) && StoryIndex == SoundManagerParameter.StoryIndex)
147 {
148 CurrentStepVODataTable = SoundManagerParameter.DependentSoundTable;
149 return;
150 }
151 }
152 }
153
154 if (StepVODataTablesArray.Num() != 0)
155 {
156 if (StepVODataTablesArray.IsValidIndex(StoryIndex))
157 {
159 }
160 else if (StepVODataTablesArray[0])
161 {
163 UE_LOG(LogTemp, Warning, TEXT("SoundManager - StepVODataTablesArray didn't have StoryIndex value, zero array element is selected"));
164 }
165 else
166 UE_LOG(LogTemp, Error, TEXT("SoundManager - CurrentStepVODataTable wasn't set up"));
167 }
168 else
169 UE_LOG(LogTemp, Error, TEXT("SoundManager - StepVODataTablesArray is empty!"));
170
171 if (StepHintVODataTablesArray.Num() != 0)
172 {
173 if (StepHintVODataTablesArray.IsValidIndex(StoryIndex))
174 {
176 }
177 else if (StepHintVODataTablesArray[0])
178 {
180 UE_LOG(LogTemp, Warning, TEXT("SoundManager - StepVODataTablesArray didn't have StoryIndex value, zero array element is selected"));
181 }
182 else
183 UE_LOG(LogTemp, Error, TEXT("SoundManager - CurrentStepHintVODataTable wasn't set up"));
184 }
185 else
186 UE_LOG(LogTemp, Warning, TEXT("SoundManager - StepHintVODataTablesArray is empty!"));
187}
#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.
FStoryStep CurrentStep
Event used to call to play sound.
USoundCue * MySoundCue
TArray< FBackgroundSound > BackgroundSounds
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (EditCondition="bPlayBackgroundSound",...
float GeneralSoundVolumeMultiplier
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, meta = (ClampMin = 0.f), Category = "SoundManager")
void OnStepChange(FText stepName)
Play SFX sound (don't interrupt others)
void PlaySound(USoundCue *soundToPlay)
UFUNCTION(BlueprintCallable, Category = "Play Sound")
TArray< UDataTable * > StepVODataTablesArray
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Components")
USoundCue * GetSoundBasedOnStep(FText stepName, UDataTable *DataTable)
Retrieves a sound cue based on the step name.
float SFXVolumeMultiplier
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, meta = (ClampMin = 0.f), Category = "SoundManager")
float BackgroundVolumeMultiplier
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, meta = (ClampMin = 0.f, EditCondition="bPlayBackground...
FOnVOEndPlaying OnVoEndPlaying
UPROPERTY(BlueprintAssignable)
void PlayBackgroundSound(USoundBase *soundToPlay, float volumeMultiplier=1.f, float pitchMultiplier=1.f, float startTime=0.f, USoundConcurrency *concurrencySettings=nullptr, AActor *owningActor=nullptr, bool bIsUISound=false)
Play sound based on the new step.
UAudioComponent * AudioComponent
UPROPERTY(BlueprintReadWrite, Category = "Components")
UDataTable * CurrentStepHintVODataTable
UPROPERTY(BlueprintReadWrite, Category = "Components")
bool bPlayBackgroundSound
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "SoundManager")
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")
void PlaySFXSound(USoundBase *soundToPlay)
Play independent background sound (don't interrupt others)
static int GetNextStoryIndex()
UFUNCTION(BlueprintCallable)
static bool IsSpecificParametersExist(TArray< FText > SpecificParameters)
UFUNCTION(BlueprintCallable)
Represents a parameter used by the Background Sound.
Represents a Step Value Object used for storing step data in a data table.
USoundCue * SoundCue
UPROPERTY(EditAnywhere, BlueprintReadOnly)
FText StepName
UPROPERTY(EditAnywhere, BlueprintReadOnly)
FText StepName
UPROPERTY(BlueprintReadWrite, EditAnywhere)