196 lines
4.8 KiB
C#
196 lines
4.8 KiB
C#
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<int, AudioBase> musicAudio;
|
|
protected Dictionary<int, AudioBase> soundsAudio;
|
|
|
|
protected Queue<AudioBase> freeMusicAudio;
|
|
protected Queue<AudioBase> freeSoundsAudio;
|
|
|
|
protected List<int> toBeRemoved;
|
|
|
|
protected bool Initialized = false;
|
|
|
|
public readonly int NoneID = -1;
|
|
|
|
/// <summary>
|
|
/// When set to true, new Audios that have the same audio clip as any other Audio, will be ignored
|
|
/// </summary>
|
|
public bool IgnoreDuplicateMusic { get; set; }
|
|
|
|
/// <summary>
|
|
/// When set to true, new Audios that have the same audio clip as any other Audio, will be ignored
|
|
/// </summary>
|
|
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<int, AudioBase>();
|
|
soundsAudio = new Dictionary<int, AudioBase>();
|
|
freeMusicAudio = new Queue<AudioBase>();
|
|
freeSoundsAudio = new Queue<AudioBase>();
|
|
|
|
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<int> keys = new List<int>(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<int>(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()
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
} |