Stratkit Audio Assets¶
Module with components to be able to use Audio Assets
How to Setup Channel Modules:¶
* Create a prefab with AudioSources as child. (e.g. DefaultAudioAssetPlayerPrefab)
* Add to this prefab the component AudioAssetPlayer.
* Create an AudioModule Instance and assign the prefabs. (e.g. assign DefaultAudioAssetPlayerPrefab)
(There are 2 modules implementations included by default, AudioModuleCombatAudioChannel and AudioModuleDefaultAudioChannel)
* Add module to bootstrap to initialize with the correct world.
(On persistent worlds remember to setup the module to be DontDestroyOnLoad)
How to Setup Volume Module:¶
* In the MixerGroup expose the property Volume for the each mixer group you wnt to control and rename the property to something similar to {MixerGroupName}Volume, this can actually be configured at the AudioMixerGroupVolumeSaveKey but that is the default.
* Create a AudioMixerGroupVolumeSaveKey scriptable object for each MixerGroup you want to control Volume.
* Assign each MixerGroup to each AudioMixerGroupVolumeSaveKey
* Change default values if needed on AudioMixerGroupVolumeSaveKey for save key and or exposed parameter if needed otherwise leave as default.
* Create a AudioVolumeModule add to bootstrap, the faster this initialize the faster we will have the sound volume at the correct value.
* Assign all the AudioMixerGroupVolumeSaveKey to the AudioVolumeModule, so all of them get properly initialized.
* Somewhere in UI create as many sliders UIVolumeSliderController as AudioMixerGroupVolumeSaveKey in order to control the volume from a UI.Slider.
How to Play a Sound:¶
* Get a reference to your sound with AssetReferenceT<AudioAsset>.
* Get an IAudioAssetPlayerECS (Can use a serialized reference to get an instance) and play the reference with a given world.
(There are 2 IAudioAssetPlayerECS implementations included with this package, CombatAudioChannelPlayer and DefaultAudioChannelPlayer)
How to Setup Default Settings:¶
This is useful so whenever we add a PlaySoundOnEnableDisable
or PlaySoundOnClick
it will be pre-assigned with the default sounds that can be overriden.
* Create a `PlaySoundOnEnableDisableDefaultSettings` ScripableObject in your project and configure accordingly
* Create a `PlaySoundOnClickDefaultSettings` ScripableObject in your project and configure accordingly
How to place a 3D sound¶
* Go into the map scene you want to place a sound, make sure it is the Hand Placed.
* It is recommended to create a GameObject root named AmbienceSounds, and mark it as Static.
* Create child GameObjects with the component Play3DSound and AudioSource component and Assign the AudioSource you want to play into the Play3DSound component.
FAQ¶
* Why are there multiple Modules (AudioModuleDefaultAudioChannel / AudioModuleCombatAudioChannel)?
- This is because that way we can control how many AudioSources each module has, the combat module for example is expected to have less AudioSources, thus, limiting the amount of sounds played in a combat and avoid too much "noise"
* Why are this modules on the Persistence ECS World AND the Map ECS World?
- This is so we can play some sounds always regadless of where they are called from (Persistence) or things on the map like ambience or 3D sounds that may be looping but we want to stop them when unloading the map as that would destroy the AudioSource's owner.