-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSoundNodeCuePlayer.cpp
152 lines (134 loc) · 3.42 KB
/
SoundNodeCuePlayer.cpp
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "SoundNodeCuePlayer.h"
#include "ActiveSound.h"
#include "Sound/SoundCue.h"
#include "FrameworkObjectVersion.h"
#define LOCTEXT_NAMESPACE "SoundNodeCuePlayer"
void USoundNodeCuePlayer::Serialize(FArchive& Ar)
{
Super::Serialize(Ar);
Ar.UsingCustomVersion(FFrameworkObjectVersion::GUID);
if (Ar.CustomVer(FFrameworkObjectVersion::GUID) >= FFrameworkObjectVersion::HardSoundReferences)
{
if (Ar.IsLoading())
{
Ar << SoundCue;
}
else if (Ar.IsSaving())
{
USoundCue* HardReference = (ShouldHardReferenceAsset() ? SoundCue : nullptr);
Ar << HardReference;
}
}
}
void USoundNodeCuePlayer::LoadAsset(bool bAddToRoot)
{
if (IsAsyncLoading())
{
SoundCue = SoundCueAssetPtr.Get();
if (!SoundCue)
{
const FString LongPackageName = SoundCueAssetPtr.GetLongPackageName();
if (!LongPackageName.IsEmpty())
{
bAsyncLoading = true;
LoadPackageAsync(LongPackageName, FLoadPackageAsyncDelegate::CreateUObject(this, &USoundNodeCuePlayer::OnSoundCueLoaded, bAddToRoot));
}
}
else if (bAddToRoot)
{
SoundCue->AddToRoot();
}
if (SoundCue)
{
SoundCue->AddToCluster(this);
}
}
else
{
SoundCue = SoundCueAssetPtr.LoadSynchronous();
if (SoundCue)
{
if (bAddToRoot)
{
SoundCue->AddToRoot();
}
SoundCue->AddToCluster(this);
}
}
}
void USoundNodeCuePlayer::ClearAssetReferences()
{
SoundCue = nullptr;
}
void USoundNodeCuePlayer::OnSoundCueLoaded(const FName& PackageName, UPackage* Package, EAsyncLoadingResult::Type Result, bool bAddToRoot)
{
if (Result == EAsyncLoadingResult::Succeeded)
{
SoundCue = SoundCueAssetPtr.Get();
if (SoundCue)
{
if (bAddToRoot)
{
SoundCue->AddToRoot();
}
SoundCue->AddToCluster(this);
}
}
bAsyncLoading = false;
}
#if WITH_EDITOR
void USoundNodeCuePlayer::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
if (PropertyChangedEvent.Property && PropertyChangedEvent.Property->GetFName() == GET_MEMBER_NAME_CHECKED(USoundNodeCuePlayer, SoundCueAssetPtr))
{
LoadAsset();
}
}
#endif
void USoundNodeCuePlayer::ParseNodes(FAudioDevice* AudioDevice, const UPTRINT NodeWaveInstanceHash, FActiveSound& ActiveSound, const FSoundParseParameters& ParseParams, TArray<FWaveInstance*>& WaveInstances)
{
if (bAsyncLoading)
{
UE_LOG(LogAudio, Verbose, TEXT("Asynchronous load of %s not complete in USoundNodeCuePlayer::ParseNodes, will attempt to play later."), *GetFullNameSafe(this));
// We're still loading so don't stop this active sound yet
ActiveSound.bFinished = false;
return;
}
if (SoundCue && !IsTheSameSoundCue())
{
SoundCue->Parse(AudioDevice, NodeWaveInstanceHash, ActiveSound, ParseParams, WaveInstances);
}
}
float USoundNodeCuePlayer::GetDuration()
{
return SoundCue->Duration;
}
#if WITH_EDITOR
FText USoundNodeCuePlayer::GetTitle() const
{
FText SoundCueName;
if (SoundCue)
{
SoundCueName = FText::FromString(SoundCue->GetFName().ToString());
}
else
{
SoundCueName = LOCTEXT("NoSoundCue", "NONE");
}
FText Title;
FFormatNamedArguments Arguments;
Arguments.Add(TEXT("Description"), Super::GetTitle());
Arguments.Add(TEXT("SoundCueName"), SoundCueName);
Title = FText::Format(LOCTEXT("SoundCueDescription", "{Description} : {SoundCueName}"), Arguments);
return Title;
}
#endif
bool USoundNodeCuePlayer::IsTheSameSoundCue() const
{
if (SoundCueAssetPtr)
{
return SoundCueAssetPtr.GetAssetName() == CuePlayerAssetPtr.GetAssetName();
}
return false;
}
#undef LOCTEXT_NAMESPACE