1111
This commit is contained in:
@@ -2,25 +2,27 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Threading.Tasks;
|
||||
using Cysharp.Threading.Tasks;
|
||||
|
||||
namespace Stary.Evo.AudioCore
|
||||
{
|
||||
public static class AudioCoreManager
|
||||
{
|
||||
private static AudioSourcePool audioSourcePool;
|
||||
private static VoicePlayer Voice;
|
||||
private static SFXPlayer SFX;
|
||||
private static IAudio Voice;
|
||||
private static IAudio SFX;
|
||||
private static MusicPlayer Music;
|
||||
|
||||
public static void Initialize()
|
||||
private static IResources Resources;
|
||||
|
||||
public static void Initialize(IResources resources)
|
||||
{
|
||||
audioSourcePool = new AudioSourcePool();
|
||||
// 初始化播放器
|
||||
Voice = new VoicePlayer(audioSourcePool);
|
||||
SFX = new SFXPlayer(audioSourcePool);
|
||||
Music = new MusicPlayer(audioSourcePool);
|
||||
Resources = resources;
|
||||
Voice = new VoicePlayer(Resources);
|
||||
SFX = new SFXPlayer(Resources);
|
||||
Music = new MusicPlayer(Resources);
|
||||
|
||||
}
|
||||
|
||||
|
||||
#region 语音
|
||||
|
||||
/// <summary>
|
||||
@@ -32,8 +34,12 @@ namespace Stary.Evo.AudioCore
|
||||
/// [audio3DMaxDistance:3D音频最大距离]}</param>
|
||||
public static void PlayVoice(AudioData audioData)
|
||||
{
|
||||
if(Voice == null) Initialize();
|
||||
Voice.Play(audioData);
|
||||
if (Voice == null)
|
||||
{
|
||||
Debug.LogError("AudioCoreManager: Voice is null, please initialize it first.");
|
||||
return;
|
||||
}
|
||||
Voice?.Play(audioData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -45,9 +51,13 @@ namespace Stary.Evo.AudioCore
|
||||
/// [audio3DMaxDistance:3D音频最大距离],
|
||||
/// [cancellationToken:异步取消令牌]}</param>
|
||||
/// <returns></returns>
|
||||
public static Task PlayAsyncVoice(AudioData audioData)
|
||||
public static UniTask PlayAsyncVoice(AudioData audioData)
|
||||
{
|
||||
if(Voice == null) Initialize();
|
||||
if (Voice == null)
|
||||
{
|
||||
Debug.LogError("AudioCoreManager: Voice is null, please initialize it first.");
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
return Voice.PlayAsync(audioData);
|
||||
}
|
||||
|
||||
@@ -56,7 +66,11 @@ namespace Stary.Evo.AudioCore
|
||||
/// </summary>
|
||||
public static void StopVoice()
|
||||
{
|
||||
if(Voice == null) return;
|
||||
if (Voice == null)
|
||||
{
|
||||
Debug.LogError("AudioCoreManager: Voice is null, please initialize it first.");
|
||||
return;
|
||||
}
|
||||
Voice.Stop();
|
||||
}
|
||||
|
||||
@@ -73,7 +87,11 @@ namespace Stary.Evo.AudioCore
|
||||
/// [audio3DMaxDistance:3D音频最大距离]}</param>
|
||||
public static void PlaySFX(AudioData audioData)
|
||||
{
|
||||
if(SFX == null) Initialize();
|
||||
if (SFX == null)
|
||||
{
|
||||
Debug.LogError("AudioCoreManager: SFX is null, please initialize it first.");
|
||||
return;
|
||||
}
|
||||
SFX.Play(audioData);
|
||||
}
|
||||
|
||||
@@ -82,7 +100,11 @@ namespace Stary.Evo.AudioCore
|
||||
/// </summary>
|
||||
public static void StopAllSFX()
|
||||
{
|
||||
if(SFX == null) return;
|
||||
if (SFX == null)
|
||||
{
|
||||
Debug.LogError("AudioCoreManager: SFX is null, please initialize it first.");
|
||||
return;
|
||||
}
|
||||
AudioData audioData = new AudioData();
|
||||
SFX.Stop();
|
||||
}
|
||||
@@ -99,31 +121,43 @@ namespace Stary.Evo.AudioCore
|
||||
/// [audio3DMaxDistance:3D音频最大距离]}</param>
|
||||
public static void PlayMusic(AudioData audioData)
|
||||
{
|
||||
if(Music == null) Initialize();
|
||||
if (Music == null)
|
||||
{
|
||||
Debug.LogError("AudioCoreManager: Music is null, please initialize it first.");
|
||||
return;
|
||||
}
|
||||
Music.Play(audioData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置背景音乐音量
|
||||
/// Bgm设置自然过渡到指定音量
|
||||
/// </summary>
|
||||
/// <param name="audioData">{[volume:音量], [fadeDuration:自然过渡时间]}</param>
|
||||
public static void SetMusicVolume(AudioData audioData)
|
||||
/// <param name="fadeDuration"></param>
|
||||
/// <param name="targetVolume"></param>
|
||||
/// <returns></returns>
|
||||
public static void SetMusicVolume(float fadeDuration, float targetVolume)
|
||||
{
|
||||
if(Music == null) return;
|
||||
Music.SetMusicVolume(audioData);
|
||||
if (Music == null)
|
||||
{
|
||||
Debug.LogError("AudioCoreManager: Music is null, please initialize it first.");
|
||||
return;
|
||||
}
|
||||
Music.SetMusicVolume(fadeDuration, targetVolume);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 停止播放背景音乐
|
||||
/// </summary>
|
||||
/// <param name="fadeDuration">自然过渡时间</param>
|
||||
public static void StopMusic(float fadeDuration = 1f)
|
||||
{
|
||||
if(Music == null) return;
|
||||
AudioData audioData = new AudioData();
|
||||
audioData.fadeDuration = fadeDuration;
|
||||
Music.Stop(audioData);
|
||||
if (Music == null)
|
||||
{
|
||||
Debug.LogError("AudioCoreManager: Music is null, please initialize it first.");
|
||||
return;
|
||||
}
|
||||
Music.Stop();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -132,14 +166,14 @@ namespace Stary.Evo.AudioCore
|
||||
/// 重新初始化
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static void Reinitialize()
|
||||
public static void Dispose()
|
||||
{
|
||||
if (audioSourcePool == null) Initialize();
|
||||
|
||||
StopVoice();
|
||||
StopAllSFX();
|
||||
StopMusic();
|
||||
Voice = null;
|
||||
SFX = null;
|
||||
Music = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user