using System.Collections; using System.Collections.Generic; using UnityEngine; namespace BF { public class SoundManager : ManagerBase { static SoundManager instance; public static SoundManager Create() { BFLog.LogAssert(instance == null, "This method only allows BFMain to call once"); instance = new SoundManager(); return instance; } private SoundManager() { } private static GameObject soundObject; private static AudioSource musicAudioSource; public override void Init() { soundObject = new GameObject("SoundManager"); soundObject.AddComponent(); UnityEngine.GameObject.DontDestroyOnLoad(soundObject); } public AudioSource getMusicAudioSource() { if (musicAudioSource == null) { musicAudioSource = soundObject.AddComponent(); } return musicAudioSource; } public AudioSource addEffectAudioSource() { AudioSource effectAudioSource = soundObject.AddComponent(); return effectAudioSource; } public void clearAudioSource() { AudioSource[] audioSources = soundObject.GetComponents(); for (int i = 0; i < audioSources.Length; i++) { GameObject.Destroy(audioSources[i]); } } } }