using System.Collections.Generic; using Cysharp.Threading.Tasks; using UnityEngine; using UnityEngine.SceneManagement; public enum AudioType { MUSIC, SOUND } public enum ClipType { AudioClip, CriwareClip } namespace PhxhSDK { public abstract class AudioMgrBase : IStart, IInitable, IUpdatable, IAudioPlay { public GameObject initGameObject; private float _vol; private float _musicVol; private float _soundVol; protected Dictionary musicAudio; protected Dictionary soundsAudio; protected Queue freeMusicAudio; protected Queue freeSoundsAudio; protected List toBeRemoved; protected bool Initialized = false; public readonly int NoneID = -1; /// /// When set to true, new Audios that have the same audio clip as any other Audio, will be ignored /// public bool IgnoreDuplicateMusic { get; set; } /// /// When set to true, new Audios that have the same audio clip as any other Audio, will be ignored /// public bool IgnoreDuplicateSounds { get; set; } public float GlobalVolume { get { return _vol; } set { _vol = value; } } public float GlobalMusicVolume { get { return _musicVol; } set { _musicVol = value; } } public float GlobalSoundsVolume { get { return _soundVol; } set { _soundVol = value; } } public void SetMusicEnable(bool isEnable) { GlobalMusicVolume = isEnable ? 1 : 0; } public void SetSoundEnable(bool isEnable) { GlobalSoundsVolume = isEnable ? 1 : 0; } public void SetVolumeEnable(bool isEnable) { GlobalVolume = isEnable ? 1 : 0; } public virtual void Start() { } public virtual void Init() { if (!Initialized) { musicAudio = new Dictionary(); soundsAudio = new Dictionary(); freeMusicAudio = new Queue(); freeSoundsAudio = new Queue(); IgnoreDuplicateMusic = false; IgnoreDuplicateSounds = false; Initialized = true; } SceneManager.sceneLoaded += OnSceneLoaded; } public virtual void Release() { } public virtual void Update(float dt) { } protected void OnSceneLoaded(Scene scene, LoadSceneMode mode) { // List keys = new List(musicAudio.Keys); // foreach (var key in keys) // { // if (musicAudio.ContainsKey(key)) // { // var music = musicAudio[key]; // if (!music.persist && music.activated) // { // Object.Destroy(music.RootGo); // musicAudio.Remove(key); // } // } // } // // keys = new List(soundsAudio.Keys); // foreach (var key in keys) // { // if (musicAudio.ContainsKey(key)) // { // var sound = soundsAudio[key]; // if (!sound.persist && sound.activated) // { // Object.Destroy(sound.RootGo); // musicAudio.Remove(key); // } // } // } } public void ResumeAll() { ResumeAllMusic(); ResumeAllSounds(); } public virtual void ResumeAllMusic() { } public virtual void ResumeAllSounds() { } public virtual void PauseAll() { PauseAllMusic(); PauseAllSounds(); } public virtual void PauseAllMusic() { } public virtual void PauseAllSounds() { } public virtual void StopAll(float fadeOutSeconds = -1.0f) { StopAllMusic(fadeOutSeconds); StopAllSounds(); } public virtual void StopAllMusic(float fadeOutSeconds = -1.0f) { } public virtual void StopAllSounds() { } } }