TopDown Engine v4.5
Loading...
Searching...
No Matches
MoreMountains.TopDownEngine.SoundManager Class Reference

This persistent singleton handles sound playing. More...

Inheritance diagram for MoreMountains.TopDownEngine.SoundManager:
MoreMountains.Tools.MMPersistentSingleton< T > MoreMountains.Tools.MMEventListener< T > MoreMountains.Tools.MMEventListener< T > MoreMountains.Tools.MMEventListenerBase MoreMountains.Tools.MMEventListenerBase

Public Member Functions

virtual void PlayBackgroundMusic (AudioSource musicAudioSource, bool loop=true)
 Plays a background music. Only one background music can be active at a time.
virtual AudioSource PlaySound (AudioClip sfx, Vector3 location, bool loop=false)
 Plays a sound.
virtual AudioSource PlaySound (AudioClip sfx, Vector3 location, float pitch, float pan, float spatialBlend=0.0f, float volumeMultiplier=1.0f, bool loop=false, AudioSource reuseSource=null, AudioMixerGroup audioGroup=null, int priority=128)
 Advanced PlaySound method.
virtual void StopLoopingSound (AudioSource source)
 Stops the looping sounds if there are any.
virtual void MusicOn ()
 Sets the music setting to On.
virtual void MusicOff ()
 Sets the Music setting to Off.
virtual void SfxOn ()
 Sets the SFX setting to On.
virtual void SfxOff ()
 Sets the SFX setting to Off.
virtual void StopAllLoopingSounds ()
 Stops all currently looping sounds.
virtual void UnmuteBackgroundMusic ()
 Unmutes the background music.
virtual void MuteBackgroundMusic ()
 Mutes the background music.
bool IsBackgroundMusicInScene ()
bool IsBackgroundMusicPlaying ()
virtual void PauseBackgroundMusic ()
virtual void ResumeBackgroundMusic ()
virtual void StopBackgroundMusic ()
virtual void OnMMEvent (TopDownEngineEvent engineEvent)
 Watches for pause events to cut the sound on pause.
virtual void OnMMSfxEvent (AudioClip clipToPlay, AudioMixerGroup audioGroup=null, float volume=1f, float pitch=1f, int priority=128)
 When we grab a sfx event, we play the corresponding sound.
virtual void OnMMEvent (MMGameEvent gameEvent)
 Watches for game events to mute sfx if needed.
Public Member Functions inherited from MoreMountains.Tools.MMEventListener< T >
void OnMMEvent (T eventType)

Public Attributes

SoundSettings Settings
 the current sound settings
float MusicVolume = 0.3f
 the music volume
float SfxVolume = 1f
 the sound fx volume
bool MuteSfxOnPause = true
 whether or not Sfx should be muted when the game is paused
Public Attributes inherited from MoreMountains.Tools.MMPersistentSingleton< T >
bool AutomaticallyUnparentOnAwake = true
 if this is true, this singleton will auto detach if it finds itself parented on awake

Protected Member Functions

virtual void SetMusic (bool status)
 Sets the music on/off setting based on the value in parameters This value will be saved, and any music played after that setting change will comply.
virtual void SetSfx (bool status)
 Sets the SFX on/off setting based on the value in parameters This value will be saved, and any SFX played after that setting change will comply.
virtual void SaveSoundSettings ()
 Saves the sound settings to file.
virtual void LoadSoundSettings ()
 Loads the sound settings from file (if found)
virtual void ResetSoundSettings ()
 Resets the sound settings by destroying the save file.
virtual void MuteAllSfx ()
 Mutes all sfx currently playing.
virtual void UnmuteAllSfx ()
 Unmutes all sfx currently playing.
virtual void OnEnable ()
 On enable we start listening for events.
virtual void OnDisable ()
 On disable we stop listening for events.
Protected Member Functions inherited from MoreMountains.Tools.MMPersistentSingleton< T >
virtual void Awake ()
 On awake, we check if there's already a copy of the object in the scene. If there's one, we destroy it.
virtual void InitializeSingleton ()
 Initializes the singleton.

Protected Attributes

AudioSource _backgroundMusic
List< AudioSource > _loopingSounds = new List<AudioSource>()
Protected Attributes inherited from MoreMountains.Tools.MMPersistentSingleton< T >
bool _enabled

Static Protected Attributes

const string _saveFolderName = "TopDownEngine/"
const string _saveFileName = "sound.settings"
Static Protected Attributes inherited from MoreMountains.Tools.MMPersistentSingleton< T >
static T _instance

Properties

virtual bool IsMusicOn [get, set]
virtual bool IsSfxOn [get, set]
Properties inherited from MoreMountains.Tools.MMPersistentSingleton< T >
static bool HasInstance [get]
static T Current [get]
static T Instance [get]
 Singleton design pattern.

Detailed Description

This persistent singleton handles sound playing.

Member Function Documentation

◆ IsBackgroundMusicInScene()

bool MoreMountains.TopDownEngine.SoundManager.IsBackgroundMusicInScene ( )

◆ IsBackgroundMusicPlaying()

bool MoreMountains.TopDownEngine.SoundManager.IsBackgroundMusicPlaying ( )

◆ LoadSoundSettings()

virtual void MoreMountains.TopDownEngine.SoundManager.LoadSoundSettings ( )
protectedvirtual

Loads the sound settings from file (if found)

◆ MusicOff()

virtual void MoreMountains.TopDownEngine.SoundManager.MusicOff ( )
virtual

Sets the Music setting to Off.

◆ MusicOn()

virtual void MoreMountains.TopDownEngine.SoundManager.MusicOn ( )
virtual

Sets the music setting to On.

◆ MuteAllSfx()

virtual void MoreMountains.TopDownEngine.SoundManager.MuteAllSfx ( )
protectedvirtual

Mutes all sfx currently playing.

◆ MuteBackgroundMusic()

virtual void MoreMountains.TopDownEngine.SoundManager.MuteBackgroundMusic ( )
virtual

Mutes the background music.

◆ OnDisable()

virtual void MoreMountains.TopDownEngine.SoundManager.OnDisable ( )
protectedvirtual

On disable we stop listening for events.

◆ OnEnable()

virtual void MoreMountains.TopDownEngine.SoundManager.OnEnable ( )
protectedvirtual

On enable we start listening for events.

◆ OnMMEvent() [1/2]

virtual void MoreMountains.TopDownEngine.SoundManager.OnMMEvent ( MMGameEvent gameEvent)
virtual

Watches for game events to mute sfx if needed.

Parameters
gameEvent

◆ OnMMEvent() [2/2]

virtual void MoreMountains.TopDownEngine.SoundManager.OnMMEvent ( TopDownEngineEvent engineEvent)
virtual

Watches for pause events to cut the sound on pause.

Parameters
engineEvent

◆ OnMMSfxEvent()

virtual void MoreMountains.TopDownEngine.SoundManager.OnMMSfxEvent ( AudioClip clipToPlay,
AudioMixerGroup audioGroup = null,
float volume = 1f,
float pitch = 1f,
int priority = 128 )
virtual

When we grab a sfx event, we play the corresponding sound.

Parameters
sfxEvent

◆ PauseBackgroundMusic()

virtual void MoreMountains.TopDownEngine.SoundManager.PauseBackgroundMusic ( )
virtual

◆ PlayBackgroundMusic()

virtual void MoreMountains.TopDownEngine.SoundManager.PlayBackgroundMusic ( AudioSource musicAudioSource,
bool loop = true )
virtual

Plays a background music. Only one background music can be active at a time.

Parameters
ClipYour audio clip.

◆ PlaySound() [1/2]

virtual AudioSource MoreMountains.TopDownEngine.SoundManager.PlaySound ( AudioClip sfx,
Vector3 location,
bool loop = false )
virtual

Plays a sound.

Returns
An audiosource
Parameters
sfxThe sound clip you want to play.
locationThe location of the sound.
loopIf set to true, the sound will loop.

◆ PlaySound() [2/2]

virtual AudioSource MoreMountains.TopDownEngine.SoundManager.PlaySound ( AudioClip sfx,
Vector3 location,
float pitch,
float pan,
float spatialBlend = 0::0f,
float volumeMultiplier = 1::0f,
bool loop = false,
AudioSource reuseSource = null,
AudioMixerGroup audioGroup = null,
int priority = 128 )
virtual

Advanced PlaySound method.

Parameters
sfx
location
pitch
pan
spatialBlend
volumeMultiplier
loop
reuseSource
audioGroup
soundFadeInDuration
Returns

◆ ResetSoundSettings()

virtual void MoreMountains.TopDownEngine.SoundManager.ResetSoundSettings ( )
protectedvirtual

Resets the sound settings by destroying the save file.

◆ ResumeBackgroundMusic()

virtual void MoreMountains.TopDownEngine.SoundManager.ResumeBackgroundMusic ( )
virtual

◆ SaveSoundSettings()

virtual void MoreMountains.TopDownEngine.SoundManager.SaveSoundSettings ( )
protectedvirtual

Saves the sound settings to file.

◆ SetMusic()

virtual void MoreMountains.TopDownEngine.SoundManager.SetMusic ( bool status)
protectedvirtual

Sets the music on/off setting based on the value in parameters This value will be saved, and any music played after that setting change will comply.

Parameters
status

◆ SetSfx()

virtual void MoreMountains.TopDownEngine.SoundManager.SetSfx ( bool status)
protectedvirtual

Sets the SFX on/off setting based on the value in parameters This value will be saved, and any SFX played after that setting change will comply.

Parameters
status

◆ SfxOff()

virtual void MoreMountains.TopDownEngine.SoundManager.SfxOff ( )
virtual

Sets the SFX setting to Off.

◆ SfxOn()

virtual void MoreMountains.TopDownEngine.SoundManager.SfxOn ( )
virtual

Sets the SFX setting to On.

◆ StopAllLoopingSounds()

virtual void MoreMountains.TopDownEngine.SoundManager.StopAllLoopingSounds ( )
virtual

Stops all currently looping sounds.

◆ StopBackgroundMusic()

virtual void MoreMountains.TopDownEngine.SoundManager.StopBackgroundMusic ( )
virtual

◆ StopLoopingSound()

virtual void MoreMountains.TopDownEngine.SoundManager.StopLoopingSound ( AudioSource source)
virtual

Stops the looping sounds if there are any.

Parameters
sourceSource.

◆ UnmuteAllSfx()

virtual void MoreMountains.TopDownEngine.SoundManager.UnmuteAllSfx ( )
protectedvirtual

Unmutes all sfx currently playing.

◆ UnmuteBackgroundMusic()

virtual void MoreMountains.TopDownEngine.SoundManager.UnmuteBackgroundMusic ( )
virtual

Unmutes the background music.

Member Data Documentation

◆ _backgroundMusic

AudioSource MoreMountains.TopDownEngine.SoundManager._backgroundMusic
protected

◆ _loopingSounds

List<AudioSource> MoreMountains.TopDownEngine.SoundManager._loopingSounds = new List<AudioSource>()
protected

◆ _saveFileName

const string MoreMountains.TopDownEngine.SoundManager._saveFileName = "sound.settings"
staticprotected

◆ _saveFolderName

const string MoreMountains.TopDownEngine.SoundManager._saveFolderName = "TopDownEngine/"
staticprotected

◆ MusicVolume

float MoreMountains.TopDownEngine.SoundManager.MusicVolume = 0.3f

the music volume

◆ MuteSfxOnPause

bool MoreMountains.TopDownEngine.SoundManager.MuteSfxOnPause = true

whether or not Sfx should be muted when the game is paused

◆ Settings

SoundSettings MoreMountains.TopDownEngine.SoundManager.Settings

the current sound settings

◆ SfxVolume

float MoreMountains.TopDownEngine.SoundManager.SfxVolume = 1f

the sound fx volume

Property Documentation

◆ IsMusicOn

virtual bool MoreMountains.TopDownEngine.SoundManager.IsMusicOn
getset

◆ IsSfxOn

virtual bool MoreMountains.TopDownEngine.SoundManager.IsSfxOn
getset

The documentation for this class was generated from the following file:
  • H:/Code/MoreMountains/topdownengine/Assets/TopDownEngine/Common/Scripts/Managers/SoundManager.cs