|
@@ -14,18 +14,37 @@ namespace Core.Audio
|
|
private Map<string, AudioBundleInfo> _allAduionBundleInfos = new Map<string, AudioBundleInfo>();
|
|
private Map<string, AudioBundleInfo> _allAduionBundleInfos = new Map<string, AudioBundleInfo>();
|
|
|
|
|
|
private Queue<AudioSourcePool> _audioSourcePools = new Queue<AudioSourcePool>();
|
|
private Queue<AudioSourcePool> _audioSourcePools = new Queue<AudioSourcePool>();
|
|
- private Map<string, AudioSourcePool> _currPlayAudio = new Map<string, AudioSourcePool>();
|
|
|
|
|
|
+ private Map<string, List<AudioSourcePool>> _currPlayAudio = new Map<string, List<AudioSourcePool>>();
|
|
|
|
|
|
private List<string> _bgmQueue = new List<string>();
|
|
private List<string> _bgmQueue = new List<string>();
|
|
private AudioSourcePool _currBgm;
|
|
private AudioSourcePool _currBgm;
|
|
|
|
|
|
private List<string> _audion = new List<string>();
|
|
private List<string> _audion = new List<string>();
|
|
|
|
|
|
|
|
+ public float AudionVolume
|
|
|
|
+ {
|
|
|
|
+ get => _audionVolume;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public float BgmVolume
|
|
|
|
+ {
|
|
|
|
+ get => _bgmVolume;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private float _audionVolume = 1;
|
|
|
|
+ private float _bgmVolume = 1;
|
|
|
|
+
|
|
public AudioManager()
|
|
public AudioManager()
|
|
{
|
|
{
|
|
// UIAudio.AudioPlayManager = this;
|
|
// UIAudio.AudioPlayManager = this;
|
|
_root = new GameObject();
|
|
_root = new GameObject();
|
|
_root.name = "audio";
|
|
_root.name = "audio";
|
|
|
|
+ AudioListener audioListener = GameObject.FindObjectOfType<AudioListener>();
|
|
|
|
+ if (audioListener == null)
|
|
|
|
+ {
|
|
|
|
+ _root.AddComponent<AudioListener>();
|
|
|
|
+ }
|
|
|
|
+
|
|
Object.DontDestroyOnLoad(_root);
|
|
Object.DontDestroyOnLoad(_root);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -35,6 +54,14 @@ namespace Core.Audio
|
|
/// <param name="value"></param>
|
|
/// <param name="value"></param>
|
|
public void SetAudioValue(float value)
|
|
public void SetAudioValue(float value)
|
|
{
|
|
{
|
|
|
|
+ _audionVolume = value;
|
|
|
|
+ for (_currPlayAudio.Begin(); _currPlayAudio.Next();)
|
|
|
|
+ {
|
|
|
|
+ for (int i = 0; i < _currPlayAudio.Value.Count; i++)
|
|
|
|
+ {
|
|
|
|
+ _currPlayAudio.Value[i].Setvolume();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -43,6 +70,16 @@ namespace Core.Audio
|
|
/// <param name="value"></param>
|
|
/// <param name="value"></param>
|
|
public void SetBgmValue(float value)
|
|
public void SetBgmValue(float value)
|
|
{
|
|
{
|
|
|
|
+ _bgmVolume = value;
|
|
|
|
+ for (_currPlayAudio.Begin(); _currPlayAudio.Next();)
|
|
|
|
+ {
|
|
|
|
+ for (int i = 0; i < _currPlayAudio.Value.Count; i++)
|
|
|
|
+ {
|
|
|
|
+ _currPlayAudio.Value[i].Setvolume();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ _currBgm?.Setvolume();
|
|
}
|
|
}
|
|
|
|
|
|
public async CTask Init()
|
|
public async CTask Init()
|
|
@@ -76,9 +113,13 @@ namespace Core.Audio
|
|
AudionSettingConfig.AudionConfig audionConfig = audionSettingConfig.configs[i];
|
|
AudionSettingConfig.AudionConfig audionConfig = audionSettingConfig.configs[i];
|
|
if (_allAduionBundleInfos.TryGetValue(audionConfig.audionClipName, out AudioBundleInfo abi))
|
|
if (_allAduionBundleInfos.TryGetValue(audionConfig.audionClipName, out AudioBundleInfo abi))
|
|
{
|
|
{
|
|
- if (_currPlayAudio.TryGetValue(audionConfig.audionClipName, out AudioSourcePool audioSourcePool))
|
|
|
|
|
|
+ if (_currPlayAudio.TryGetValue(audionConfig.audionClipName,
|
|
|
|
+ out List<AudioSourcePool> audioSourcePool))
|
|
{
|
|
{
|
|
- audioSourcePool.Finish();
|
|
|
|
|
|
+ for (int j = 0; j < audioSourcePool.Count; j++)
|
|
|
|
+ {
|
|
|
|
+ audioSourcePool[i].Finish();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
abi.Dispose();
|
|
abi.Dispose();
|
|
@@ -118,7 +159,10 @@ namespace Core.Audio
|
|
_audioSourcePools.Enqueue(audioSourcePool);
|
|
_audioSourcePools.Enqueue(audioSourcePool);
|
|
}
|
|
}
|
|
|
|
|
|
- _currPlayAudio.Remove(audioSourcePool.CurrPlayName);
|
|
|
|
|
|
+ if (_currPlayAudio.TryGetValue(audioSourcePool.CurrPlayName, out List<AudioSourcePool> audioSourcePools))
|
|
|
|
+ {
|
|
|
|
+ audioSourcePools.Remove(audioSourcePool);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
private AudioSourcePool GetAudioSourcePool()
|
|
private AudioSourcePool GetAudioSourcePool()
|
|
@@ -166,7 +210,7 @@ namespace Core.Audio
|
|
_currBgm = GetAudioSourcePool();
|
|
_currBgm = GetAudioSourcePool();
|
|
}
|
|
}
|
|
|
|
|
|
- _currBgm.Play(bgmName, audioClip, true, audioBundleInfo._volume);
|
|
|
|
|
|
+ _currBgm.Play(bgmName, true, audioClip, true, audioBundleInfo._volume);
|
|
}
|
|
}
|
|
|
|
|
|
public void PauseBGM()
|
|
public void PauseBGM()
|
|
@@ -226,14 +270,29 @@ namespace Core.Audio
|
|
|
|
|
|
using (await CoroutineLockComponent.Instance.Wait(audionName))
|
|
using (await CoroutineLockComponent.Instance.Wait(audionName))
|
|
{
|
|
{
|
|
- if (_currPlayAudio.TryGetValue(audionName, out AudioSourcePool asp))
|
|
|
|
|
|
+ if (_currPlayAudio.TryGetValue(audionName, out List<AudioSourcePool> asp))
|
|
{
|
|
{
|
|
- if (asp.Progress() < 0.2)
|
|
|
|
|
|
+ for (int i = 0; i < asp.Count; i++)
|
|
{
|
|
{
|
|
- return null;
|
|
|
|
|
|
+ AudioSourcePool a = asp[i];
|
|
|
|
+ a.Setvolume(a.AudioVolume - 0.33f);
|
|
|
|
+ if (a.AudioVolume <= 0)
|
|
|
|
+ {
|
|
|
|
+ a.Finish();
|
|
|
|
+ i--;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-
|
|
|
|
- asp.Finish();
|
|
|
|
|
|
+ // if (asp.Progress() < 0.2)
|
|
|
|
+ // {
|
|
|
|
+ // return null;
|
|
|
|
+ // }
|
|
|
|
+ //
|
|
|
|
+ // asp.Finish();
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ asp = new List<AudioSourcePool>();
|
|
|
|
+ _currPlayAudio.Add(audionName, asp);
|
|
}
|
|
}
|
|
|
|
|
|
AudioBundleInfo audioBundleInfo = await GetAduionBundleInfo(audionName);
|
|
AudioBundleInfo audioBundleInfo = await GetAduionBundleInfo(audionName);
|
|
@@ -245,8 +304,8 @@ namespace Core.Audio
|
|
}
|
|
}
|
|
|
|
|
|
AudioSourcePool audioSourcePool = GetAudioSourcePool();
|
|
AudioSourcePool audioSourcePool = GetAudioSourcePool();
|
|
- audioSourcePool.Play(audionName, audioClip, isLoop, audioBundleInfo._volume,speed);
|
|
|
|
- _currPlayAudio[audionName] = audioSourcePool;
|
|
|
|
|
|
+ audioSourcePool.Play(audionName, false, audioClip, isLoop, audioBundleInfo._volume, speed);
|
|
|
|
+ asp.Add(audioSourcePool);
|
|
return audioSourcePool;
|
|
return audioSourcePool;
|
|
}
|
|
}
|
|
}
|
|
}
|