Documentation for the Unity C# Library
Loading...
Searching...
No Matches
EazySoundManager.cs
Go to the documentation of this file.
1using UnityEngine;
2using System.Collections.Generic;
3using UnityEngine.SceneManagement;
4using System.Linq;
5using System;
6
7namespace Hellmade.Sound
8{
12 public class EazySoundManager : MonoBehaviour
13 {
17 public static GameObject Gameobject
18 {
19 get { return Instance.gameObject; }
20 }
21
25 public static bool IgnoreDuplicateMusic { get; set; }
26
30 public static bool IgnoreDuplicateSounds { get; set; }
31
35 public static bool IgnoreDuplicateUISounds { get; set; }
36
40 public static float GlobalVolume { get; set; }
41
45 public static float GlobalMusicVolume { get; set; }
46
50 public static float GlobalSoundsVolume { get; set; }
51
55 public static float GlobalUISoundsVolume { get; set; }
56
57 private static EazySoundManager instance = null;
58
59 private static Dictionary<int, Audio> musicAudio;
60 private static Dictionary<int, Audio> soundsAudio;
61 private static Dictionary<int, Audio> UISoundsAudio;
62 private static Dictionary<int, Audio> audioPool;
63
64 public static event Action<Audio> AudioStopped;
65
66 private static bool initialized = false;
67
69 {
70 get
71 {
72 if (instance == null)
73 {
74 instance = (EazySoundManager)FindObjectOfType(typeof(EazySoundManager));
75 if (instance == null)
76 {
77 // Create gameObject and add component
78 instance = (new GameObject("EazySoundManager")).AddComponent<EazySoundManager>();
79 }
80 }
81
82 return instance;
83 }
84 }
85
87 {
88 Instance.Init();
89 }
90
94 private void Init()
95 {
96 if (!initialized)
97 {
98 musicAudio = new Dictionary<int, Audio>();
99 soundsAudio = new Dictionary<int, Audio>();
100 UISoundsAudio = new Dictionary<int, Audio>();
101 audioPool = new Dictionary<int, Audio>();
102
103 GlobalVolume = 1;
107
108 IgnoreDuplicateMusic = false;
109 IgnoreDuplicateSounds = false;
111
112 initialized = true;
113 DontDestroyOnLoad(this);
114 }
115 }
116
117 private void OnEnable()
118 {
119 SceneManager.sceneLoaded += OnSceneLoaded;
120 }
121
122 private void OnDisable()
123 {
124 SceneManager.sceneLoaded -= OnSceneLoaded;
125 }
126
132 private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
133 {
134 // Stop and remove all non-persistent audio
138 }
139
146
152 private static Dictionary<int, Audio> GetAudioTypeDictionary(Audio.AudioType audioType)
153 {
154 Dictionary<int, Audio> audioDict = new Dictionary<int, Audio>();
155 switch (audioType)
156 {
157 case Audio.AudioType.Music:
158 audioDict = musicAudio;
159 break;
160 case Audio.AudioType.Sound:
161 audioDict = soundsAudio;
162 break;
163 case Audio.AudioType.UISound:
164 audioDict = UISoundsAudio;
165 break;
166 }
167
168 return audioDict;
169 }
170
177 {
178 switch (audioType)
179 {
180 case Audio.AudioType.Music:
182 case Audio.AudioType.Sound:
184 case Audio.AudioType.UISound:
186 default:
187 return false;
188 }
189 }
190
195 private static void UpdateAllAudio(Dictionary<int, Audio> audioDict)
196 {
197 // Go through all audios and update them
198 List<int> keys = new List<int>(audioDict.Keys);
199
200 foreach (int key in keys)
201 {
202 Audio audio = audioDict[key];
203 audio.Update();
204
205 // Remove it if it is no longer active (playing)
206 if (!audio.IsPlaying && !audio.Paused)
207 {
208 AudioStopped?.Invoke(audio);
209
210 Destroy(audio.AudioSource);
211
212 // Add it to the audio pool in case it needs to be referenced in the future
213 audioPool.Add(key, audio);
214 audio.Pooled = true;
215 audioDict.Remove(key);
216 }
217 }
218 }
219
224 private static void RemoveNonPersistAudio(Dictionary<int, Audio> audioDict)
225 {
226 // Go through all audios and remove them if they should not persist through scenes
227 List<int> keys = new List<int>(audioDict.Keys);
228 foreach (int key in keys)
229 {
230 Audio audio = audioDict[key];
231 if (!audio.Persist && audio.Activated)
232 {
233 Destroy(audio.AudioSource);
234 audioDict.Remove(key);
235 }
236 }
237
238 // Go through all audios in the audio pool and remove them if they should not persist through scenes
239 keys = new List<int>(audioPool.Keys);
240 foreach (int key in keys)
241 {
242 Audio audio = audioPool[key];
243 if (!audio.Persist && audio.Activated)
244 {
245 audioPool.Remove(key);
246 }
247 }
248 }
249
256 public static bool RestoreAudioFromPool(Audio.AudioType audioType, int audioID)
257 {
258 if (audioPool.ContainsKey(audioID))
259 {
260 Dictionary<int, Audio> audioDict = GetAudioTypeDictionary(audioType);
261 audioDict.Add(audioID, audioPool[audioID]);
262 audioPool.Remove(audioID);
263
264 return true;
265 }
266
267 return false;
268 }
269
270 #region GetAudio Functions
271
277 public static Audio GetAudio(int audioID)
278 {
279 Audio audio;
280
281 audio = GetMusicAudio(audioID);
282 if (audio != null)
283 {
284 return audio;
285 }
286
287 audio = GetSoundAudio(audioID);
288 if (audio != null)
289 {
290 return audio;
291 }
292
293 audio = GetUISoundAudio(audioID);
294 if (audio != null)
295 {
296 return audio;
297 }
298
299 return null;
300 }
301
302 public static Audio GetAudio(string name)
303 {
304 Audio audio;
305
306 audio = GetMusicAudio(name);
307 if (audio != null)
308 {
309 return audio;
310 }
311
312 audio = GetSoundAudio(name);
313 if (audio != null)
314 {
315 return audio;
316 }
317
318 audio = GetUISoundAudio(name);
319 if (audio != null)
320 {
321 return audio;
322 }
323
324 return null;
325 }
326
332 public static Audio GetAudio(AudioClip audioClip)
333 {
334 Audio audio = GetMusicAudio(audioClip);
335 if (audio != null)
336 {
337 return audio;
338 }
339
340 audio = GetSoundAudio(audioClip);
341 if (audio != null)
342 {
343 return audio;
344 }
345
346 audio = GetUISoundAudio(audioClip);
347 if (audio != null)
348 {
349 return audio;
350 }
351
352 return null;
353 }
354
360 public static Audio GetMusicAudio(int audioID)
361 {
362 return GetAudio(Audio.AudioType.Music, true, audioID);
363 }
364
370 public static Audio GetMusicAudio(AudioClip audioClip)
371 {
372 return GetAudio(Audio.AudioType.Music, true, audioClip);
373 }
374
380 public static Audio GetSoundAudio(int audioID)
381 {
382 return GetAudio(Audio.AudioType.Sound, true, audioID);
383 }
384
385 public static Audio GetMusicAudio(string name)
386 {
387 return GetAudio(Audio.AudioType.Music, true, name);
388 }
389
390 public static Audio GetSoundAudio(string name)
391 {
392 return GetAudio(Audio.AudioType.Sound, true, name);
393 }
394
395 public static Audio GetUISoundAudio(string name)
396 {
397 return GetAudio(Audio.AudioType.UISound, true, name);
398 }
399
405 public static Audio GetSoundAudio(AudioClip audioClip)
406 {
407 return GetAudio(Audio.AudioType.Sound, true, audioClip);
408 }
409
415 public static Audio GetUISoundAudio(int audioID)
416 {
417 return GetAudio(Audio.AudioType.UISound, true, audioID);
418 }
419
425 public static Audio GetUISoundAudio(AudioClip audioClip)
426 {
427 return GetAudio(Audio.AudioType.UISound, true, audioClip);
428 }
429
430 private static Audio GetAudio(Audio.AudioType audioType, bool usePool, int audioID)
431 {
432 Dictionary<int, Audio> audioDict = GetAudioTypeDictionary(audioType);
433
434 if (audioDict.ContainsKey(audioID))
435 {
436 return audioDict[audioID];
437 }
438
439 if (usePool && audioPool.ContainsKey(audioID) && audioPool[audioID].Type == audioType)
440 {
441 return audioPool[audioID];
442 }
443
444 return null;
445 }
446
447 private static Audio GetAudio(Audio.AudioType audioType, bool usePool, string name)
448 {
449 Dictionary<int, Audio> audioDict = GetAudioTypeDictionary(audioType);
450
451 var audio = audioDict.SingleOrDefault(x => x.Value.Name == name);
452
453 return audio.Value;
454 }
455
456 private static Audio GetAudio(Audio.AudioType audioType, bool usePool, AudioClip audioClip)
457 {
458 Dictionary<int, Audio> audioDict = GetAudioTypeDictionary(audioType);
459
460 List<int> audioTypeKeys = new List<int>(audioDict.Keys);
461 List<int> poolKeys = new List<int>(audioPool.Keys);
462 List<int> keys = usePool ? audioTypeKeys.Concat(poolKeys).ToList() : audioTypeKeys;
463 foreach (int key in keys)
464 {
465 Audio audio = null;
466 if (audioDict.ContainsKey(key))
467 {
468 audio = audioDict[key];
469 }
470 else if (audioPool.ContainsKey(key))
471 {
472 audio = audioPool[key];
473 }
474
475 if (audio == null)
476 {
477 return null;
478 }
479
480 if (audio.Clip == audioClip && audio.Type == audioType)
481 {
482 return audio;
483 }
484 }
485
486 return null;
487 }
488
489 #endregion
490
491 #region Prepare Function
492
498 public static int PrepareMusic(AudioClip clip)
499 {
500 return PrepareAudio(Audio.AudioType.Music, clip, 1f, false, false, 1f, 1f, -1f, null);
501 }
502
509 public static int PrepareMusic(AudioClip clip, float volume)
510 {
511 return PrepareAudio(Audio.AudioType.Music, clip, volume, false, false, 1f, 1f, -1f, null);
512 }
513
522 public static int PrepareMusic(AudioClip clip, float volume, bool loop, bool persist)
523 {
524 return PrepareAudio(Audio.AudioType.Music, clip, volume, loop, persist, 1f, 1f, -1f, null);
525 }
526
537 public static int PrepareMusic(AudioClip clip, float volume, bool loop, bool persist, float fadeInSeconds,
538 float fadeOutSeconds)
539 {
540 return PrepareAudio(Audio.AudioType.Music, clip, volume, loop, persist, fadeInSeconds, fadeOutSeconds, -1f,
541 null);
542 }
543
556 public static int PrepareMusic(AudioClip clip, float volume, bool loop, bool persist, float fadeInSeconds,
557 float fadeOutSeconds, float currentMusicfadeOutSeconds, Transform sourceTransform)
558 {
559 return PrepareAudio(Audio.AudioType.Music, clip, volume, loop, persist, fadeInSeconds, fadeOutSeconds,
560 currentMusicfadeOutSeconds, sourceTransform);
561 }
562
568 public static int PrepareSound(AudioClip clip, string name)
569 {
570 return PrepareAudio(Audio.AudioType.Sound, clip, 1f, false, false, 0f, 0f, -1f, null);
571 }
572
579 public static int PrepareSound(AudioClip clip, string name, float volume)
580 {
581 return PrepareAudio(Audio.AudioType.Sound, clip, volume, false, false, 0f, 0f, -1f, null);
582 }
583
590 public static int PrepareSound(AudioClip clip, string name, bool loop)
591 {
592 return PrepareAudio(Audio.AudioType.Sound, clip, 1f, loop, false, 0f, 0f, -1f, null);
593 }
594
603 public static int PrepareSound(AudioClip clip, string name, float volume, bool loop, Transform sourceTransform)
604 {
605 return PrepareAudio(name, Audio.AudioType.Sound, clip, volume, loop, false, 0f, 0f, -1f, sourceTransform);
606 }
607
613 public static int PrepareUISound(AudioClip clip, string name)
614 {
615 return PrepareAudio(name, Audio.AudioType.UISound, clip, 1f, false, false, 0f, 0f, -1f, null);
616 }
617
624 public static int PrepareUISound(AudioClip clip, string name, float volume)
625 {
626 return PrepareAudio(name, Audio.AudioType.UISound, clip, volume, false, false, 0f, 0f, -1f, null);
627 }
628
629 private static int PrepareAudio(string name, Audio.AudioType audioType, AudioClip clip, float volume, bool loop,
630 bool persist, float fadeInSeconds, float fadeOutSeconds, float currentMusicfadeOutSeconds,
631 Transform sourceTransform)
632 {
633 if (clip == null)
634 {
635 Debug.LogError("[Eazy Sound Manager] Audio clip is null", clip);
636 }
637
638 Dictionary<int, Audio> audioDict = GetAudioTypeDictionary(audioType);
639 bool ignoreDuplicateAudio = GetAudioTypeIgnoreDuplicateSetting(audioType);
640
641 if (ignoreDuplicateAudio)
642 {
643 Audio duplicateAudio = GetAudio(audioType, true, clip);
644 if (duplicateAudio != null)
645 {
646 return duplicateAudio.AudioID;
647 }
648 }
649
650 // Create the audioSource
651 Audio audio = new Audio(name, audioType, clip, loop, persist, volume, fadeInSeconds, fadeOutSeconds,
652 sourceTransform);
653
654 // Add it to dictionary
655 audioDict.Add(audio.AudioID, audio);
656
657 return audio.AudioID;
658 }
659
660 private static int PrepareAudio(Audio.AudioType audioType, AudioClip clip, float volume, bool loop,
661 bool persist, float fadeInSeconds, float fadeOutSeconds, float currentMusicfadeOutSeconds,
662 Transform sourceTransform)
663 {
664 if (clip == null)
665 {
666 Debug.LogError("[Eazy Sound Manager] Audio clip is null", clip);
667 }
668
669 Dictionary<int, Audio> audioDict = GetAudioTypeDictionary(audioType);
670 bool ignoreDuplicateAudio = GetAudioTypeIgnoreDuplicateSetting(audioType);
671
672 if (ignoreDuplicateAudio)
673 {
674 Audio duplicateAudio = GetAudio(audioType, true, clip);
675 if (duplicateAudio != null)
676 {
677 return duplicateAudio.AudioID;
678 }
679 }
680
681 // Create the audioSource
682 Audio audio = new Audio(string.Empty, audioType, clip, loop, persist, volume, fadeInSeconds, fadeOutSeconds,
683 sourceTransform);
684
685 // Add it to dictionary
686 audioDict.Add(audio.AudioID, audio);
687
688 return audio.AudioID;
689 }
690
691 #endregion
692
693 #region Play Functions
694
700 public static int PlayMusic(AudioClip clip)
701 {
702 return PlayAudio(Audio.AudioType.Music, clip, 1f, false, false, 1f, 1f, -1f, null);
703 }
704
711 public static int PlayMusic(AudioClip clip, float volume)
712 {
713 return PlayAudio(Audio.AudioType.Music, clip, volume, false, false, 1f, 1f, -1f, null);
714 }
715
724 public static int PlayMusic(AudioClip clip, float volume, bool loop, bool persist)
725 {
726 return PlayAudio(Audio.AudioType.Music, clip, volume, loop, persist, 1f, 1f, -1f, null);
727 }
728
739 public static int PlayMusic(AudioClip clip, float volume, bool loop, bool persist, float fadeInSeconds,
740 float fadeOutSeconds)
741 {
742 return PlayAudio(Audio.AudioType.Music, clip, volume, loop, persist, fadeInSeconds, fadeOutSeconds, -1f,
743 null);
744 }
745
758 public static int PlayMusic(AudioClip clip, float volume, bool loop, bool persist, float fadeInSeconds,
759 float fadeOutSeconds, float currentMusicfadeOutSeconds, Transform sourceTransform)
760 {
761 return PlayAudio(Audio.AudioType.Music, clip, volume, loop, persist, fadeInSeconds, fadeOutSeconds,
762 currentMusicfadeOutSeconds, sourceTransform);
763 }
764
765 public static int PlaySound(AudioClip clip,string name)
766 {
767 return PlayAudio(Audio.AudioType.Sound, clip, 1f, false, false, 0f, 0f, -1f, null);
768 }
769
770 public static int PlaySound(AudioClip clip, string name, float volume)
771 {
772 return PlayAudio(Audio.AudioType.Sound, clip, volume, false, false, 0f, 0f, -1f, null);
773 }
774
781 public static int PlaySound(AudioClip clip, string name, bool loop)
782 {
783 return PlayAudio(name,Audio.AudioType.Sound, clip, 1f, loop, false, 0f, 0f, -1f, null);
784 }
785
786 public static int PlaySound(AudioClip clip, string name, float volume, bool loop)
787 {
788 return PlayAudio(name,Audio.AudioType.Sound, clip, volume, loop, false, 0f, 0f, -1f, null);
789 }
790
799 public static int PlaySound(AudioClip clip, string name, float volume, bool loop, Transform sourceTransform)
800 {
801 return PlayAudio(name,Audio.AudioType.Sound, clip, volume, loop, false, 0f, 0f, -1f, sourceTransform);
802 }
803
809 public static int PlayUISound(AudioClip clip)
810 {
811 return PlayAudio(Audio.AudioType.UISound, clip, 1f, false, false, 0f, 0f, -1f, null);
812 }
813
820 public static int PlayUISound(AudioClip clip, float volume)
821 {
822 return PlayAudio(Audio.AudioType.UISound, clip, volume, false, false, 0f, 0f, -1f, null);
823 }
824
825 private static int PlayAudio(Audio.AudioType audioType, AudioClip clip, float volume, bool loop, bool persist,
826 float fadeInSeconds, float fadeOutSeconds, float currentMusicfadeOutSeconds, Transform sourceTransform)
827 {
828 int audioID = PrepareAudio(audioType, clip, volume, loop, persist, fadeInSeconds, fadeOutSeconds,
829 currentMusicfadeOutSeconds, sourceTransform);
830
831 // Stop all current music playing
832 if (audioType == Audio.AudioType.Music)
833 {
834 StopAllMusic(currentMusicfadeOutSeconds);
835 }
836
837 GetAudio(audioType, false, audioID).Play();
838
839 return audioID;
840 }
841
842 private static int PlayAudio(string name,Audio.AudioType audioType, AudioClip clip, float volume, bool loop, bool persist,
843 float fadeInSeconds, float fadeOutSeconds, float currentMusicfadeOutSeconds, Transform sourceTransform)
844 {
845 int audioID = PrepareAudio(name,audioType, clip, volume, loop, persist, fadeInSeconds, fadeOutSeconds,
846 currentMusicfadeOutSeconds, sourceTransform);
847
848 // Stop all current music playing
849 if (audioType == Audio.AudioType.Music)
850 {
851 StopAllMusic(currentMusicfadeOutSeconds);
852 }
853
854 GetAudio(audioType, false, audioID).Play();
855
856 return audioID;
857 }
858
859 #endregion
860
861 #region Stop Functions
862
866 public static void StopAll()
867 {
868 StopAll(-1f);
869 }
870
875 public static void StopAll(float musicFadeOutSeconds)
876 {
877 StopAllMusic(musicFadeOutSeconds);
880 }
881
885 public static void StopAllMusic()
886 {
887 StopAllAudio(Audio.AudioType.Music, -1f);
888 }
889
894 public static void StopAllMusic(float fadeOutSeconds)
895 {
896 StopAllAudio(Audio.AudioType.Music, fadeOutSeconds);
897 }
898
902 public static void StopAllSounds()
903 {
904 StopAllAudio(Audio.AudioType.Sound, -1f);
905 }
906
910 public static void StopAllUISounds()
911 {
912 StopAllAudio(Audio.AudioType.UISound, -1f);
913 }
914
915 private static void StopAllAudio(Audio.AudioType audioType, float fadeOutSeconds)
916 {
917 Dictionary<int, Audio> audioDict = GetAudioTypeDictionary(audioType);
918
919 List<int> keys = new List<int>(audioDict.Keys);
920 foreach (int key in keys)
921 {
922 Audio audio = audioDict[key];
923 if (fadeOutSeconds > 0)
924 {
925 audio.FadeOutSeconds = fadeOutSeconds;
926 }
927
928 audio.Stop();
929 }
930 }
931
932 #endregion
933
934 #region Pause Functions
935
939 public static void PauseAll()
940 {
944 }
945
949 public static void PauseAllMusic()
950 {
952 }
953
957 public static void PauseAllSounds()
958 {
960 }
961
965 public static void PauseAllUISounds()
966 {
968 }
969
970 private static void PauseAllAudio(Audio.AudioType audioType)
971 {
972 Dictionary<int, Audio> audioDict = GetAudioTypeDictionary(audioType);
973
974 List<int> keys = new List<int>(audioDict.Keys);
975 foreach (int key in keys)
976 {
977 Audio audio = audioDict[key];
978 audio.Pause();
979 }
980 }
981
982 #endregion
983
984 #region Resume Functions
985
989 public static void ResumeAll()
990 {
994 }
995
999 public static void ResumeAllMusic()
1000 {
1002 }
1003
1007 public static void ResumeAllSounds()
1008 {
1010 }
1011
1015 public static void ResumeAllUISounds()
1016 {
1018 }
1019
1020 private static void ResumeAllAudio(Audio.AudioType audioType)
1021 {
1022 Dictionary<int, Audio> audioDict = GetAudioTypeDictionary(audioType);
1023
1024 List<int> keys = new List<int>(audioDict.Keys);
1025 foreach (int key in keys)
1026 {
1027 Audio audio = audioDict[key];
1028 audio.Resume();
1029 }
1030 }
1031
1032 #endregion
1033 }
1034}
The audio object.
Definition Audio.cs:10
void Play()
Start playing audio clip from the beginning.
Definition Audio.cs:407
AudioSource AudioSource
The audio source that is responsible for this audio. Do not modify the audiosource directly as it cou...
Definition Audio.cs:56
bool IsPlaying
Whether the audio is currently playing.
Definition Audio.cs:26
void Update()
Update loop of the Audio. This is automatically called from the sound manager itself....
Definition Audio.cs:538
bool Paused
Whether the audio is paused.
Definition Audio.cs:31
void Stop()
Stop playing audio clip.
Definition Audio.cs:448
AudioClip Clip
Audio clip to play/is playing.
Definition Audio.cs:81
void Pause()
Pause playing audio clip.
Definition Audio.cs:460
AudioType Type
The type of the Audio.
Definition Audio.cs:21
AudioType
Enum representing the type of audio.
Definition Audio.cs:305
void Resume()
Resume playing audio clip.
Definition Audio.cs:478
bool Activated
Whether the audio is created and updated at least once.
Definition Audio.cs:41
int AudioID
The ID of the Audio.
Definition Audio.cs:16
bool Persist
Whether the audio persists in between scene changes.
Definition Audio.cs:288
Static class responsible for playing and managing audio and sounds.
static int PrepareAudio(string name, Audio.AudioType audioType, AudioClip clip, float volume, bool loop, bool persist, float fadeInSeconds, float fadeOutSeconds, float currentMusicfadeOutSeconds, Transform sourceTransform)
static void PauseAllMusic()
Pause all music playing.
static void RemoveNonPersistAudio(Dictionary< int, Audio > audioDict)
Remove all non-persistant audios from an audio dictionary.
static void ResumeAll()
Resume all audio playing.
static int PrepareSound(AudioClip clip, string name, float volume, bool loop, Transform sourceTransform)
Prepares and initializes a sound fx.
static Audio GetSoundAudio(AudioClip audioClip)
Returns the first occurrence of sound Audio that plays the given audioClip. Returns null if no such A...
static int PrepareUISound(AudioClip clip, string name)
Prepares and initializes a UI sound fx.
static void ResumeAllUISounds()
Resume all UI sound fx playing.
static void StopAllUISounds()
Stop all UI sound fx playing.
static Audio GetAudio(AudioClip audioClip)
Returns the first occurrence of Audio that plays the given audioClip. Returns null if no such Audio i...
static void StopAllMusic(float fadeOutSeconds)
Stop all music playing.
static float GlobalSoundsVolume
Global sounds volume.
static Dictionary< int, Audio > audioPool
static int PrepareSound(AudioClip clip, string name, bool loop)
Prepares and initializes a sound fx.
static Dictionary< int, Audio > soundsAudio
static Audio GetUISoundAudio(AudioClip audioClip)
Returns the first occurrence of UI sound Audio that plays the given audioClip. Returns null if no suc...
static int PlayMusic(AudioClip clip, float volume)
Play background music.
static Audio GetAudio(Audio.AudioType audioType, bool usePool, AudioClip audioClip)
static int PlayMusic(AudioClip clip)
Play background music.
static bool RestoreAudioFromPool(Audio.AudioType audioType, int audioID)
Restores and re-adds a pooled audio to its corresponding audio dictionary.
static bool IgnoreDuplicateMusic
When set to true, new music audios that have the same audio clip as any other music audios,...
static int PrepareMusic(AudioClip clip, float volume, bool loop, bool persist, float fadeInSeconds, float fadeOutSeconds, float currentMusicfadeOutSeconds, Transform sourceTransform)
Prepares and initializes background music.
static int PrepareSound(AudioClip clip, string name, float volume)
Prepares and initializes a sound fx.
static int PlaySound(AudioClip clip, string name, float volume, bool loop)
static bool IgnoreDuplicateUISounds
When set to true, new UI sound audios that have the same audio clip as any other UI sound audios,...
static EazySoundManager instance
void OnSceneLoaded(Scene scene, LoadSceneMode mode)
Event triggered when a new scene is loaded.
static Audio GetUISoundAudio(string name)
static void StopAllMusic()
Stop all music playing.
static int PlaySound(AudioClip clip, string name, float volume)
static int PlaySound(AudioClip clip, string name, float volume, bool loop, Transform sourceTransform)
Play a sound fx.
static bool GetAudioTypeIgnoreDuplicateSetting(Audio.AudioType audioType)
Retrieves the IgnoreDuplicates setting of audios of a specified audio type.
static float GlobalVolume
Global volume.
static float GlobalUISoundsVolume
Global UI sounds volume.
static int PrepareUISound(AudioClip clip, string name, float volume)
Prepares and initializes a UI sound fx.
static int PlaySound(AudioClip clip, string name)
static GameObject Gameobject
The gameobject that the sound manager is attached to.
static Audio GetSoundAudio(string name)
static int PrepareSound(AudioClip clip, string name)
Prepares and initializes a sound fx.
static int PrepareMusic(AudioClip clip, float volume, bool loop, bool persist)
Prepares and initializes background music.
static void StopAll(float musicFadeOutSeconds)
Stop all audio playing.
static void StopAllAudio(Audio.AudioType audioType, float fadeOutSeconds)
static void StopAll()
Stop all audio playing.
static int PrepareMusic(AudioClip clip, float volume)
Prepares and initializes background music.
static int PrepareMusic(AudioClip clip)
Prepares and initializes background music.
static int PlayUISound(AudioClip clip)
Play a UI sound fx.
static int PlayMusic(AudioClip clip, float volume, bool loop, bool persist, float fadeInSeconds, float fadeOutSeconds)
Play background music.
static bool IgnoreDuplicateSounds
When set to true, new sound audios that have the same audio clip as any other sound audios,...
static void PauseAllUISounds()
Pause all UI sound fx playing.
static void UpdateAllAudio(Dictionary< int, Audio > audioDict)
Updates the state of all audios of an audio dictionary.
static Action< Audio > AudioStopped
static void ResumeAllAudio(Audio.AudioType audioType)
static Audio GetMusicAudio(AudioClip audioClip)
Returns the first occurrence of music Audio that plays the given audioClip. Returns null if no such A...
static Audio GetSoundAudio(int audioID)
Returns the sound fx Audio that has as its id the audioID if one is found, returns null if no such Au...
static Audio GetMusicAudio(int audioID)
Returns the music Audio that has as its id the audioID if one is found, returns null if no such Audio...
static Dictionary< int, Audio > UISoundsAudio
static int PlaySound(AudioClip clip, string name, bool loop)
Play a sound fx.
static void ResumeAllMusic()
Resume all music playing.
static int PlayUISound(AudioClip clip, float volume)
Play a UI sound fx.
static Audio GetMusicAudio(string name)
static void PauseAllSounds()
Pause all sound fx playing.
static Audio GetAudio(int audioID)
Returns the Audio that has as its id the audioID if one is found, returns null if no such Audio is fo...
static int PrepareAudio(Audio.AudioType audioType, AudioClip clip, float volume, bool loop, bool persist, float fadeInSeconds, float fadeOutSeconds, float currentMusicfadeOutSeconds, Transform sourceTransform)
static void StopAllSounds()
Stop all sound fx playing.
static void PauseAllAudio(Audio.AudioType audioType)
static int PlayMusic(AudioClip clip, float volume, bool loop, bool persist)
Play background music.
static int PlayAudio(Audio.AudioType audioType, AudioClip clip, float volume, bool loop, bool persist, float fadeInSeconds, float fadeOutSeconds, float currentMusicfadeOutSeconds, Transform sourceTransform)
static Audio GetUISoundAudio(int audioID)
Returns the UI sound fx Audio that has as its id the audioID if one is found, returns null if no such...
static void ResumeAllSounds()
Resume all sound fx playing.
static Dictionary< int, Audio > musicAudio
static int PlayMusic(AudioClip clip, float volume, bool loop, bool persist, float fadeInSeconds, float fadeOutSeconds, float currentMusicfadeOutSeconds, Transform sourceTransform)
Play background music.
static int PrepareMusic(AudioClip clip, float volume, bool loop, bool persist, float fadeInSeconds, float fadeOutSeconds)
Prerpares and initializes background music.
static Dictionary< int, Audio > GetAudioTypeDictionary(Audio.AudioType audioType)
Retrieves the audio dictionary based on the audioType.
static float GlobalMusicVolume
Global music volume.
static Audio GetAudio(string name)
void Init()
Initialized the sound manager.
static Audio GetAudio(Audio.AudioType audioType, bool usePool, int audioID)
static void PauseAll()
Pause all audio playing.
static Audio GetAudio(Audio.AudioType audioType, bool usePool, string name)
static int PlayAudio(string name, Audio.AudioType audioType, AudioClip clip, float volume, bool loop, bool persist, float fadeInSeconds, float fadeOutSeconds, float currentMusicfadeOutSeconds, Transform sourceTransform)
static EazySoundManager Instance