Feel  4.3
The best way to improve your game's feel and make it extra juicy
MoreMountains.Tools.MMPlaylist Class Reference

Use this class to play audiosources (usually background music but feel free to use that for anything) in sequence, with optional crossfade between songs More...

Inheritance diagram for MoreMountains.Tools.MMPlaylist:
MoreMountains.Tools.MMMonoBehaviour

Public Types

enum  PlaylistStates { PlaylistStates.Idle, PlaylistStates.Playing, PlaylistStates.Paused }
 the possible states this playlist can be in More...
 

Public Member Functions

virtual void Play ()
 Plays either the first song or resumes playing a paused one More...
 
virtual void PlayAtIndex (int songIndex)
 
virtual void QueueSongAtIndex (int songIndex)
 
virtual void Pause ()
 Pauses the current song More...
 
virtual void Stop ()
 Stops the playlist More...
 
virtual void SetLoop (bool loop)
 Will change the current track loop status More...
 
virtual void PlayNextSong ()
 Plays the next song in the playlist More...
 
virtual void PlayPreviousSong ()
 Plays the previous song in the playlist More...
 

Public Attributes

int Channel = 0
 the channel on which to broadcast orders for this playlist More...
 
List< MMPlaylistSongSongs
 the songs that this playlist will play More...
 
bool RandomOrder = false
 whether this should play in random order or not More...
 
bool RandomizeOrderSeed = true
 if this is true, random seed will be randomized by the system clock More...
 
bool Endless = true
 whether this playlist should play and loop as a whole forever or not More...
 
bool PlayOnStart = true
 whether this playlist should auto play on start or not More...
 
float VolumeMultiplier = 1f
 a global volume multiplier to apply when playing a song More...
 
bool AutoHandleApplicationPause = true
 if this is true, this playlist will automatically pause/resume OnApplicationPause, useful if you've prevented your game from running in the background More...
 
bool Persistent = false
 if this is true, this playlist will persist from scene to scene More...
 
bool AutomaticallyUnparentOnAwake = true
 if this is true, this singleton will auto detach if it finds itself parented on awake More...
 
PlaylistStates DebugCurrentState = PlaylistStates.Idle
 the current state of the playlist, debug display only More...
 
int CurrentlyPlayingIndex = -1
 the index we're currently playing More...
 
string CurrentSongName
 the name of the song that is currently playing More...
 
MMStateMachine< MMPlaylist.PlaylistStatesPlaylistState
 the current state of this playlist More...
 
bool PlayButton
 a play test button More...
 
bool PauseButton
 a pause test button More...
 
bool StopButton
 a stop test button More...
 
bool NextButton
 a next song test button More...
 
int TargetSongIndex = 0
 the index of the song to play when pressing the PlayTargetSong button More...
 
bool TargetSongButton
 a next song test button More...
 
bool QueueTargetSongButton
 a next song test button More...
 
bool SetLoopTargetSongButton
 a next song test button More...
 
bool StopLoopTargetSongButton
 a next song test button More...
 

Static Public Attributes

static bool HasInstance => _instance != null
 
static MMPlaylist Current => _instance
 

Protected Member Functions

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. More...
 
virtual void InitializeSingleton ()
 Initializes the singleton. More...
 
virtual void Start ()
 On Start we initialize our playlist More...
 
virtual void Initialization ()
 On init we initialize our state machine and start playing if needed More...
 
virtual void ChangePlaylistState (PlaylistStates newState)
 
virtual void PlayFirstSong ()
 Picks and plays the first song More...
 
virtual IEnumerator PlaySong (int index)
 Plays a new song in the playlist, and stops / fades the previous one More...
 
virtual IEnumerator Fade (int index, float duration, float initialVolume, float endVolume, bool stopAtTheEnd)
 Fades an audiosource in or out, optionnally stopping it at the end More...
 
virtual int PickNextIndex ()
 Picks the next song to play More...
 
virtual int PickPreviousIndex ()
 Picks the previous song to play More...
 
virtual void PlayTargetSong ()
 
virtual void QueueTargetSong ()
 
virtual void SetLoopTargetSong ()
 
virtual void StopLoopTargetSong ()
 
virtual void OnPlayEvent (int channel)
 
virtual void OnPauseEvent (int channel)
 
virtual void OnStopEvent (int channel)
 
virtual void OnPlayNextEvent (int channel)
 
virtual void OnPlayPreviousEvent (int channel)
 
virtual void OnPlayIndexEvent (int channel, int index)
 
virtual void OnMMPlaylistVolumeMultiplierEvent (int channel, float newVolumeMultiplier, bool applyVolumeMultiplierInstantly=false)
 
virtual void OnEnable ()
 On enable, starts listening for playlist events More...
 
virtual void OnDisable ()
 On disable, stops listening for playlist events More...
 
virtual void OnValidate ()
 On Validate, we check if our array has changed and if yes we initialize our new elements More...
 
virtual void OnApplicationPause (bool pauseStatus)
 On ApplicationPause, we pause the playlist and resume it afterwards More...
 

Protected Attributes

int _songsPlayedSoFar = 0
 
int _songsPlayedThisCycle = 0
 
Coroutine _coroutine
 
bool _shouldResumeOnApplicationPause = false
 
bool _enabled
 
int _queuedSong = -1
 
bool _firstDeserialization = true
 
int _listCount = 0
 

Static Protected Attributes

static MMPlaylist _instance
 

Properties

static MMPlaylist Instance [get]
 Singleton design pattern More...
 

Detailed Description

Use this class to play audiosources (usually background music but feel free to use that for anything) in sequence, with optional crossfade between songs

Member Enumeration Documentation

◆ PlaylistStates

the possible states this playlist can be in

Enumerator
Idle 
Playing 
Paused 

Member Function Documentation

◆ Awake()

virtual void MoreMountains.Tools.MMPlaylist.Awake ( )
protectedvirtual

On awake, we check if there's already a copy of the object in the scene. If there's one, we destroy it.

◆ ChangePlaylistState()

virtual void MoreMountains.Tools.MMPlaylist.ChangePlaylistState ( PlaylistStates  newState)
protectedvirtual

◆ Fade()

virtual IEnumerator MoreMountains.Tools.MMPlaylist.Fade ( int  index,
float  duration,
float  initialVolume,
float  endVolume,
bool  stopAtTheEnd 
)
protectedvirtual

Fades an audiosource in or out, optionnally stopping it at the end

Parameters
source
duration
initialVolume
endVolume
stopAtTheEnd
Returns

◆ Initialization()

virtual void MoreMountains.Tools.MMPlaylist.Initialization ( )
protectedvirtual

On init we initialize our state machine and start playing if needed

◆ InitializeSingleton()

virtual void MoreMountains.Tools.MMPlaylist.InitializeSingleton ( )
protectedvirtual

Initializes the singleton.

◆ OnApplicationPause()

virtual void MoreMountains.Tools.MMPlaylist.OnApplicationPause ( bool  pauseStatus)
protectedvirtual

On ApplicationPause, we pause the playlist and resume it afterwards

Parameters
pauseStatus

◆ OnDisable()

virtual void MoreMountains.Tools.MMPlaylist.OnDisable ( )
protectedvirtual

On disable, stops listening for playlist events

◆ OnEnable()

virtual void MoreMountains.Tools.MMPlaylist.OnEnable ( )
protectedvirtual

On enable, starts listening for playlist events

◆ OnMMPlaylistVolumeMultiplierEvent()

virtual void MoreMountains.Tools.MMPlaylist.OnMMPlaylistVolumeMultiplierEvent ( int  channel,
float  newVolumeMultiplier,
bool  applyVolumeMultiplierInstantly = false 
)
protectedvirtual

◆ OnPauseEvent()

virtual void MoreMountains.Tools.MMPlaylist.OnPauseEvent ( int  channel)
protectedvirtual

◆ OnPlayEvent()

virtual void MoreMountains.Tools.MMPlaylist.OnPlayEvent ( int  channel)
protectedvirtual

◆ OnPlayIndexEvent()

virtual void MoreMountains.Tools.MMPlaylist.OnPlayIndexEvent ( int  channel,
int  index 
)
protectedvirtual

◆ OnPlayNextEvent()

virtual void MoreMountains.Tools.MMPlaylist.OnPlayNextEvent ( int  channel)
protectedvirtual

◆ OnPlayPreviousEvent()

virtual void MoreMountains.Tools.MMPlaylist.OnPlayPreviousEvent ( int  channel)
protectedvirtual

◆ OnStopEvent()

virtual void MoreMountains.Tools.MMPlaylist.OnStopEvent ( int  channel)
protectedvirtual

◆ OnValidate()

virtual void MoreMountains.Tools.MMPlaylist.OnValidate ( )
protectedvirtual

On Validate, we check if our array has changed and if yes we initialize our new elements

◆ Pause()

virtual void MoreMountains.Tools.MMPlaylist.Pause ( )
virtual

Pauses the current song

◆ PickNextIndex()

virtual int MoreMountains.Tools.MMPlaylist.PickNextIndex ( )
protectedvirtual

Picks the next song to play

Returns

◆ PickPreviousIndex()

virtual int MoreMountains.Tools.MMPlaylist.PickPreviousIndex ( )
protectedvirtual

Picks the previous song to play

Returns

◆ Play()

virtual void MoreMountains.Tools.MMPlaylist.Play ( )
virtual

Plays either the first song or resumes playing a paused one

◆ PlayAtIndex()

virtual void MoreMountains.Tools.MMPlaylist.PlayAtIndex ( int  songIndex)
virtual

◆ PlayFirstSong()

virtual void MoreMountains.Tools.MMPlaylist.PlayFirstSong ( )
protectedvirtual

Picks and plays the first song

◆ PlayNextSong()

virtual void MoreMountains.Tools.MMPlaylist.PlayNextSong ( )
virtual

Plays the next song in the playlist

◆ PlayPreviousSong()

virtual void MoreMountains.Tools.MMPlaylist.PlayPreviousSong ( )
virtual

Plays the previous song in the playlist

◆ PlaySong()

virtual IEnumerator MoreMountains.Tools.MMPlaylist.PlaySong ( int  index)
protectedvirtual

Plays a new song in the playlist, and stops / fades the previous one

Parameters
index
Returns

◆ PlayTargetSong()

virtual void MoreMountains.Tools.MMPlaylist.PlayTargetSong ( )
protectedvirtual

◆ QueueSongAtIndex()

virtual void MoreMountains.Tools.MMPlaylist.QueueSongAtIndex ( int  songIndex)
virtual

◆ QueueTargetSong()

virtual void MoreMountains.Tools.MMPlaylist.QueueTargetSong ( )
protectedvirtual

◆ SetLoop()

virtual void MoreMountains.Tools.MMPlaylist.SetLoop ( bool  loop)
virtual

Will change the current track loop status

◆ SetLoopTargetSong()

virtual void MoreMountains.Tools.MMPlaylist.SetLoopTargetSong ( )
protectedvirtual

◆ Start()

virtual void MoreMountains.Tools.MMPlaylist.Start ( )
protectedvirtual

On Start we initialize our playlist

◆ Stop()

virtual void MoreMountains.Tools.MMPlaylist.Stop ( )
virtual

Stops the playlist

◆ StopLoopTargetSong()

virtual void MoreMountains.Tools.MMPlaylist.StopLoopTargetSong ( )
protectedvirtual

Member Data Documentation

◆ _coroutine

Coroutine MoreMountains.Tools.MMPlaylist._coroutine
protected

◆ _enabled

bool MoreMountains.Tools.MMPlaylist._enabled
protected

◆ _firstDeserialization

bool MoreMountains.Tools.MMPlaylist._firstDeserialization = true
protected

◆ _instance

MMPlaylist MoreMountains.Tools.MMPlaylist._instance
staticprotected

◆ _listCount

int MoreMountains.Tools.MMPlaylist._listCount = 0
protected

◆ _queuedSong

int MoreMountains.Tools.MMPlaylist._queuedSong = -1
protected

◆ _shouldResumeOnApplicationPause

bool MoreMountains.Tools.MMPlaylist._shouldResumeOnApplicationPause = false
protected

◆ _songsPlayedSoFar

int MoreMountains.Tools.MMPlaylist._songsPlayedSoFar = 0
protected

◆ _songsPlayedThisCycle

int MoreMountains.Tools.MMPlaylist._songsPlayedThisCycle = 0
protected

◆ AutoHandleApplicationPause

bool MoreMountains.Tools.MMPlaylist.AutoHandleApplicationPause = true

if this is true, this playlist will automatically pause/resume OnApplicationPause, useful if you've prevented your game from running in the background

◆ AutomaticallyUnparentOnAwake

bool MoreMountains.Tools.MMPlaylist.AutomaticallyUnparentOnAwake = true

if this is true, this singleton will auto detach if it finds itself parented on awake

◆ Channel

int MoreMountains.Tools.MMPlaylist.Channel = 0

the channel on which to broadcast orders for this playlist

◆ Current

MMPlaylist MoreMountains.Tools.MMPlaylist.Current => _instance
static

◆ CurrentlyPlayingIndex

int MoreMountains.Tools.MMPlaylist.CurrentlyPlayingIndex = -1

the index we're currently playing

◆ CurrentSongName

string MoreMountains.Tools.MMPlaylist.CurrentSongName

the name of the song that is currently playing

◆ DebugCurrentState

PlaylistStates MoreMountains.Tools.MMPlaylist.DebugCurrentState = PlaylistStates.Idle

the current state of the playlist, debug display only

◆ Endless

bool MoreMountains.Tools.MMPlaylist.Endless = true

whether this playlist should play and loop as a whole forever or not

◆ HasInstance

bool MoreMountains.Tools.MMPlaylist.HasInstance => _instance != null
static

◆ NextButton

bool MoreMountains.Tools.MMPlaylist.NextButton

a next song test button

◆ PauseButton

bool MoreMountains.Tools.MMPlaylist.PauseButton

a pause test button

◆ Persistent

bool MoreMountains.Tools.MMPlaylist.Persistent = false

if this is true, this playlist will persist from scene to scene

◆ PlayButton

bool MoreMountains.Tools.MMPlaylist.PlayButton

a play test button

◆ PlaylistState

MMStateMachine<MMPlaylist.PlaylistStates> MoreMountains.Tools.MMPlaylist.PlaylistState

the current state of this playlist

◆ PlayOnStart

bool MoreMountains.Tools.MMPlaylist.PlayOnStart = true

whether this playlist should auto play on start or not

◆ QueueTargetSongButton

bool MoreMountains.Tools.MMPlaylist.QueueTargetSongButton

a next song test button

◆ RandomizeOrderSeed

bool MoreMountains.Tools.MMPlaylist.RandomizeOrderSeed = true

if this is true, random seed will be randomized by the system clock

◆ RandomOrder

bool MoreMountains.Tools.MMPlaylist.RandomOrder = false

whether this should play in random order or not

◆ SetLoopTargetSongButton

bool MoreMountains.Tools.MMPlaylist.SetLoopTargetSongButton

a next song test button

◆ Songs

List<MMPlaylistSong> MoreMountains.Tools.MMPlaylist.Songs

the songs that this playlist will play

◆ StopButton

bool MoreMountains.Tools.MMPlaylist.StopButton

a stop test button

◆ StopLoopTargetSongButton

bool MoreMountains.Tools.MMPlaylist.StopLoopTargetSongButton

a next song test button

◆ TargetSongButton

bool MoreMountains.Tools.MMPlaylist.TargetSongButton

a next song test button

◆ TargetSongIndex

int MoreMountains.Tools.MMPlaylist.TargetSongIndex = 0

the index of the song to play when pressing the PlayTargetSong button

◆ VolumeMultiplier

float MoreMountains.Tools.MMPlaylist.VolumeMultiplier = 1f

a global volume multiplier to apply when playing a song

Property Documentation

◆ Instance

MMPlaylist MoreMountains.Tools.MMPlaylist.Instance
staticget

Singleton design pattern

The instance.


The documentation for this class was generated from the following file: