HKI Core
PausePlayer.cs
Go to the documentation of this file.
1 using UnityEngine;
2 
3 namespace HKI.Core.Audio
4 {
8  public class PausePlayer : MonoBehaviour
9  {
10  // Enums
11  [System.Serializable]
12  public enum AudioPlayerTypes
13  {
14  Music,
15  Ambient,
16  Voices,
17  FX,
18  UIFX
19  }
20 
21  // Public variables
22  [SerializeField] AudioSystem AudioSystem = null;
23 
24  [SerializeField] AudioPlayerTypes AudioPlayerType = AudioPlayerTypes.Music;
25 
26  // OnEnable function
27  void OnEnable()
28  {
29  if (AudioSystem != null)
30  {
31  switch (AudioPlayerType)
32  {
33  case AudioPlayerTypes.Music: AudioSystem.MusicAudioPlayer.PlayPlaylist(false, false); break;
34 
35  case AudioPlayerTypes.Ambient: AudioSystem.AmbientAudioPlayer.PlayPlaylist(false, false); break;
36 
37  case AudioPlayerTypes.Voices: AudioSystem.VoicesAudioPlayer.PlayPlaylist(false, false); break;
38 
39  case AudioPlayerTypes.FX: AudioSystem.FxAudioPlayer.PlayPlaylist(false, false); break;
40 
41  case AudioPlayerTypes.UIFX: AudioSystem.UiFxAudioPlayer.PlayPlaylist(false, false); break;
42  }
43  }
44  }
45 
46  // OnDisable function
47  void OnDisable()
48  {
49  if (AudioSystem != null)
50  {
51  switch (AudioPlayerType)
52  {
53  case AudioPlayerTypes.Music: if(AudioSystem.MusicAudioPlayer != null) AudioSystem.MusicAudioPlayer.PlayPlaylist(true, false); break;
54 
55  case AudioPlayerTypes.Ambient: if(AudioSystem.AmbientAudioPlayer != null) AudioSystem.AmbientAudioPlayer.PlayPlaylist(true, false); break;
56 
57  case AudioPlayerTypes.Voices: if(AudioSystem.VoicesAudioPlayer != null) AudioSystem.VoicesAudioPlayer.PlayPlaylist(true, false); break;
58 
59  case AudioPlayerTypes.FX: if(AudioSystem.FxAudioPlayer != null) AudioSystem.FxAudioPlayer.PlayPlaylist(true, false); break;
60 
61  case AudioPlayerTypes.UIFX: if(AudioSystem.UiFxAudioPlayer != null) AudioSystem.UiFxAudioPlayer.PlayPlaylist(true, false); break;
62  }
63  }
64  }
65  }
66 }
SimpleAudioPlayer VoicesAudioPlayer
Definition: AudioSystem.cs:42
SimpleAudioPlayer UiFxAudioPlayer
Definition: AudioSystem.cs:41
This MonoBehaviour allows pausing of a SoundClip on one of the general purpose AudioPlayers.
Definition: PausePlayer.cs:8
void PlayPlaylist(bool playPlaylist, bool debugLog=true)
SimpleAudioPlayer MusicAudioPlayer
Definition: AudioSystem.cs:38
The AudioSystem is responsble of the creation and access of the general purpose AudioPlayers.
Definition: AudioSystem.cs:12
SimpleAudioPlayer FxAudioPlayer
Definition: AudioSystem.cs:40
SimpleAudioPlayer AmbientAudioPlayer
Definition: AudioSystem.cs:39