114 lines
2.9 KiB
C#
114 lines
2.9 KiB
C#
using UnityEngine;
|
|
using System.Collections.Generic;
|
|
|
|
public static class AudioCoreManager
|
|
{
|
|
private static AudioSourcePool audioSourcePool;
|
|
private static VoicePlayer Voice;
|
|
private static SFXPlayer SFX;
|
|
private static MusicPlayer Music;
|
|
|
|
static AudioCoreManager()
|
|
{
|
|
audioSourcePool = new AudioSourcePool();
|
|
// 初始化播放器
|
|
Voice = new VoicePlayer(audioSourcePool);
|
|
SFX = new SFXPlayer(audioSourcePool);
|
|
Music = new MusicPlayer(audioSourcePool);
|
|
}
|
|
|
|
#region 语音
|
|
|
|
/// <summary>
|
|
/// 播放语音
|
|
/// </summary>
|
|
/// <param name="clip">音频</param>
|
|
/// <param name="onComplete">结束行为</param>
|
|
/// <param name="delay">结束行为延迟执行时间</param>
|
|
public static void PlayVoice(AudioClip clip, System.Action onComplete, float delay = 0f)
|
|
{
|
|
Voice.Play(clip, 1f, onComplete, delay);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 播放语音
|
|
/// </summary>
|
|
/// <param name="clip">音频</param>
|
|
/// <param name="volume">音量</param>
|
|
/// <param name="onComplete">结束行为</param>
|
|
/// <param name="delay">结束行为延迟执行时间</param>
|
|
public static void PlayVoice(AudioClip clip, float volume = 1f, System.Action onComplete = null, float delay = 0f)
|
|
{
|
|
Voice.Play(clip, volume, onComplete, delay);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 停止当前的语音
|
|
/// </summary>
|
|
public static void StopVoice()
|
|
{
|
|
Voice.Stop();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 音效
|
|
|
|
/// <summary>
|
|
/// 播放音效
|
|
/// </summary>
|
|
/// <param name="clip">音频</param>
|
|
/// <param name="onComplete">结束行为</param>
|
|
/// <param name="delay">结束行为延迟执行时间</param>
|
|
public static void PlaySFX(AudioClip clip, System.Action onComplete, float delay = 0f)
|
|
{
|
|
SFX.Play(clip, 1f, onComplete, delay);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 播放音效
|
|
/// </summary>
|
|
/// <param name="clip">音频</param>
|
|
/// <param name="volume">音量</param>
|
|
/// <param name="onComplete">结束行为</param>
|
|
/// <param name="delay">结束行为延迟执行时间</param>
|
|
public static void PlaySFX(AudioClip clip, float volume = 1f, System.Action onComplete = null, float delay = 0f)
|
|
{
|
|
SFX.Play(clip, volume, onComplete, delay);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 停止所有音效
|
|
/// </summary>
|
|
public static void StopAllSFX()
|
|
{
|
|
SFX.Stop();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 背景音乐
|
|
|
|
/// <summary>
|
|
/// 播放背景音乐
|
|
/// </summary>
|
|
/// <param name="clip">音频</param>
|
|
/// <param name="volume">音量</param>
|
|
/// <param name="fadeDuration">自然过渡时间</param>
|
|
public static void PlayMusic(AudioClip clip, float volume = 1f, float fadeDuration = 1f)
|
|
{
|
|
Music.Play(clip, volume, fadeDuration);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 停止播放背景音乐
|
|
/// </summary>
|
|
/// <param name="fadeDuration">自然过渡时间</param>
|
|
public static void StopMusic(float fadeDuration = 1f)
|
|
{
|
|
Music.Stop(fadeDuration);
|
|
}
|
|
|
|
#endregion
|
|
|
|
} |