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); instance->setVolume(volume);
} }
bool AudioClip::GetDestroyOnSceneExit()
{
return destroyOnSceneExit;
}
void AudioClip::SetDestroyOnSceneExit(bool value)
{
destroyOnSceneExit = value;
}
SHEventHandle SHAudioSystem::onStop(SHEventPtr onStopEvent) SHEventHandle SHAudioSystem::onStop(SHEventPtr onStopEvent)
{ {
StopAllSounds(); StopAllSounds();
@ -841,8 +851,11 @@ namespace SHADE
auto [begin, end] = audioClipLibrary.GetDenseAccess(); auto [begin, end] = audioClipLibrary.GetDenseAccess();
for (auto& it = begin; it != end; ++it) for (auto& it = begin; it != end; ++it)
{ {
it->instance->stop(FMOD_STUDIO_STOP_ALLOWFADEOUT); if(it->destroyOnSceneExit)
it->instance->release(); {
it->instance->stop(FMOD_STUDIO_STOP_ALLOWFADEOUT);
it->instance->release();
}
} }
return onSceneExitEvent->handle; return onSceneExitEvent->handle;

View File

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

View File

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