Destroy on scene exit property of AudioClipHandles

This commit is contained in:
SHAM-DP 2023-03-20 12:23:00 +08:00
parent c824f2c9e4
commit c9b284fe93
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();
@ -840,10 +850,13 @@ 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)
{
if(it->destroyOnSceneExit)
{ {
it->instance->stop(FMOD_STUDIO_STOP_ALLOWFADEOUT); it->instance->stop(FMOD_STUDIO_STOP_ALLOWFADEOUT);
it->instance->release(); 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 */
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/