Added destroy on scene exit property of AudioClipHandles #428

Merged
srishamharan merged 1 commits from SP3-129-AudioSystem into main 2023-03-20 12:53:21 +08:00
4 changed files with 34 additions and 2 deletions

View File

@ -822,6 +822,16 @@ namespace SHADE
instance->setVolume(volume);
}
bool AudioClip::GetDestroyOnSceneExit()
{
return destroyOnSceneExit;
}
void AudioClip::SetDestroyOnSceneExit(bool value)
{
destroyOnSceneExit = value;
}
SHEventHandle SHAudioSystem::onStop(SHEventPtr onStopEvent)
{
StopAllSounds();
@ -840,10 +850,13 @@ namespace SHADE
{
auto [begin, end] = audioClipLibrary.GetDenseAccess();
for (auto& it = begin; it != end; ++it)
{
if(it->destroyOnSceneExit)
{
it->instance->stop(FMOD_STUDIO_STOP_ALLOWFADEOUT);
it->instance->release();
}
}
return onSceneExitEvent->handle;
}

View File

@ -37,10 +37,13 @@ namespace SHADE
float GetParameterValue(const char* paramName);
float GetVolume();
void SetVolume(float volume);
bool GetDestroyOnSceneExit();
void SetDestroyOnSceneExit(bool value);
friend class SHAudioSystem;
private:
FMOD::Studio::EventInstance* instance = nullptr;
EntityID transformRef = MAX_EID;
bool destroyOnSceneExit = true;
};
class SH_API SHAudioSystem : public SHSystem

View File

@ -44,6 +44,16 @@ namespace SHADE
return SHResourceManagerInterface::GetAssetID(Convert::ToNative(audioClipInstHandle)).value_or(INVALID_ASSET_ID);
}
bool AudioClipHandler::DestroyOnSceneExit::get()
{
return NativeObject->GetDestroyOnSceneExit();
}
void AudioClipHandler::DestroyOnSceneExit::set(bool value)
{
NativeObject->SetDestroyOnSceneExit(value);
}
/*---------------------------------------------------------------------------------*/
/* Constructors/Destructor */
/*---------------------------------------------------------------------------------*/

View File

@ -54,6 +54,12 @@ namespace SHADE
AssetID get();
}
property bool DestroyOnSceneExit
{
bool get();
void set(bool value);
}
/*-----------------------------------------------------------------------------*/
/* Constructors/Destructor */
/*-----------------------------------------------------------------------------*/