diff --git a/Source/Engine/Audio/AudioSource.cpp b/Source/Engine/Audio/AudioSource.cpp index cb32e0967..89d1d0a5b 100644 --- a/Source/Engine/Audio/AudioSource.cpp +++ b/Source/Engine/Audio/AudioSource.cpp @@ -19,6 +19,7 @@ AudioSource::AudioSource(const SpawnParams& params) , _minDistance(1000.0f) , _loop(false) , _playOnStart(false) + , _startTime(0.0f) , _allowSpatialization(true) { Clip.Changed.Bind(this); @@ -71,6 +72,11 @@ void AudioSource::SetPlayOnStart(bool value) _playOnStart = value; } +void AudioSource::SetStartTime(float value) +{ + _startTime = value; +} + void AudioSource::SetMinDistance(float value) { value = Math::Max(0.0f, value); @@ -361,6 +367,7 @@ void AudioSource::Serialize(SerializeStream& stream, const void* otherObj) SERIALIZE_MEMBER(DopplerFactor, _dopplerFactor); SERIALIZE_MEMBER(Loop, _loop); SERIALIZE_MEMBER(PlayOnStart, _playOnStart); + SERIALIZE_MEMBER(StartTime, _startTime); SERIALIZE_MEMBER(AllowSpatialization, _allowSpatialization); } @@ -377,6 +384,7 @@ void AudioSource::Deserialize(DeserializeStream& stream, ISerializeModifier* mod DESERIALIZE_MEMBER(DopplerFactor, _dopplerFactor); DESERIALIZE_MEMBER(Loop, _loop); DESERIALIZE_MEMBER(PlayOnStart, _playOnStart); + DESERIALIZE_MEMBER(StartTime, _startTime); DESERIALIZE_MEMBER(AllowSpatialization, _allowSpatialization); DESERIALIZE(Clip); } @@ -540,5 +548,7 @@ void AudioSource::BeginPlay(SceneBeginData* data) return; #endif Play(); + if (GetStartTime() > 0) + SetTime(GetStartTime()); } } diff --git a/Source/Engine/Audio/AudioSource.h b/Source/Engine/Audio/AudioSource.h index 70cdb4180..5c0c23c03 100644 --- a/Source/Engine/Audio/AudioSource.h +++ b/Source/Engine/Audio/AudioSource.h @@ -52,6 +52,7 @@ private: float _dopplerFactor = 1.0f; bool _loop; bool _playOnStart; + float _startTime; bool _allowSpatialization; bool _clipChanged = false; @@ -148,11 +149,25 @@ public: return _playOnStart; } + /// + /// Determines the time (in seconds) at which the audio clip starts playing if Play On Start is enabled. + /// + API_PROPERTY(Attributes = "EditorOrder(51), DefaultValue(0.0f), Limit(0, float.MaxValue, 0.01f), EditorDisplay(\"Audio Source\", \"Start Time\"), VisibleIf(nameof(PlayOnStart))") + FORCE_INLINE float GetStartTime() const + { + return _startTime; + } + /// /// Determines whether the audio clip should auto play on game start. /// API_PROPERTY() void SetPlayOnStart(bool value); + /// + /// Determines the time (in seconds) at which the audio clip starts playing if Play On Start is enabled. + /// + API_PROPERTY() void SetStartTime(float value); + /// /// Gets the minimum distance at which audio attenuation starts. When the listener is closer to the source than this value, audio is heard at full volume. Once farther away the audio starts attenuating. ///