Add audio clip started and finished events to audio source
This commit is contained in:
@@ -168,7 +168,7 @@ void AudioSource::Play()
|
||||
else
|
||||
{
|
||||
// Source was nt properly added to the Audio Backend
|
||||
LOG(Warning, "Cannot play unitialized audio source.");
|
||||
LOG(Warning, "Cannot play uninitialized audio source.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -395,6 +395,9 @@ void AudioSource::Update()
|
||||
AudioBackend::Source::VelocityChanged(SourceID, _velocity);
|
||||
}
|
||||
|
||||
if (Math::NearEqual(GetTime(), _startTime) && _isActuallyPlayingSth && _startingToPlay)
|
||||
ClipStarted();
|
||||
|
||||
// Reset starting to play value once time is greater than zero
|
||||
if (_startingToPlay && GetTime() > 0.0f)
|
||||
{
|
||||
@@ -416,6 +419,7 @@ void AudioSource::Update()
|
||||
{
|
||||
Stop();
|
||||
}
|
||||
ClipFinished();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -486,6 +490,7 @@ void AudioSource::Update()
|
||||
{
|
||||
Stop();
|
||||
}
|
||||
ClipFinished();
|
||||
}
|
||||
ASSERT(_streamingFirstChunk < clip->Buffers.Count());
|
||||
|
||||
@@ -583,3 +588,11 @@ void AudioSource::BeginPlay(SceneBeginData* data)
|
||||
SetTime(GetStartTime());
|
||||
}
|
||||
}
|
||||
|
||||
void AudioSource::EndPlay()
|
||||
{
|
||||
Actor::EndPlay();
|
||||
|
||||
ClipStarted.UnbindAll();
|
||||
ClipFinished.UnbindAll();
|
||||
}
|
||||
|
||||
@@ -76,6 +76,16 @@ public:
|
||||
API_FIELD(Attributes="EditorOrder(10), DefaultValue(null), EditorDisplay(\"Audio Source\")")
|
||||
AssetReference<AudioClip> Clip;
|
||||
|
||||
/// <summary>
|
||||
/// Event fired when the audio clip starts.
|
||||
/// </summary>
|
||||
API_EVENT() Delegate<> ClipStarted;
|
||||
|
||||
/// <summary>
|
||||
/// Event fired when the audio clip finishes.
|
||||
/// </summary>
|
||||
API_EVENT() Delegate<> ClipFinished;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the velocity of the source. Determines pitch in relation to AudioListener's position. Only relevant for spatial (3D) sources.
|
||||
/// </summary>
|
||||
@@ -326,4 +336,5 @@ protected:
|
||||
void OnDisable() override;
|
||||
void OnTransformChanged() override;
|
||||
void BeginPlay(SceneBeginData* data) override;
|
||||
void EndPlay() override;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user