HKI Core
ChangePlaylist.cs
Go to the documentation of this file.
1 using UnityEngine;
2 
3 namespace HKI.Core.Audio
4 {
8  public class ChangePlaylist : 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  [SerializeField] Playlist Playlist = null;
27 
28  [SerializeField] bool PlayOnStart = false;
29 
30  [SerializeField] float PlayInSeconds = 0.0f;
31 
32  // Start function
33  void Start()
34  {
35  if (PlayOnStart)
36  Play();
37  else
38  Invoke("Play", PlayInSeconds);
39  }
40 
41  // Interface function
42  public void Play()
43  {
44  if (AudioSystem != null)
45  {
46  switch (AudioPlayerType)
47  {
48  case AudioPlayerTypes.Music: AudioSystem.MusicAudioPlayer.ChangePlaylist(Playlist, true); break;
49 
50  case AudioPlayerTypes.Ambient: AudioSystem.AmbientAudioPlayer.ChangePlaylist(Playlist, true); break;
51 
52  case AudioPlayerTypes.Voices: AudioSystem.VoicesAudioPlayer.ChangePlaylist(Playlist, true); break;
53 
54  case AudioPlayerTypes.FX: AudioSystem.FxAudioPlayer.ChangePlaylist(Playlist, true); break;
55 
56  case AudioPlayerTypes.UIFX: AudioSystem.UiFxAudioPlayer.ChangePlaylist(Playlist, true); break;
57  }
58  }
59  }
60  }
61 }
SimpleAudioPlayer VoicesAudioPlayer
Definition: AudioSystem.cs:42
This ScriptableObject contains the data of a playlist for the AudioPlayer.
Definition: Playlist.cs:19
SimpleAudioPlayer UiFxAudioPlayer
Definition: AudioSystem.cs:41
void ChangePlaylist(Playlist playlist)
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
This MonoBehaviour allows the changing of the playlist on one of the general purpose AudioPlayers...
SimpleAudioPlayer AmbientAudioPlayer
Definition: AudioSystem.cs:39