322 lines
9.0 KiB
C#
322 lines
9.0 KiB
C#
using System;
|
||
using Cysharp.Threading.Tasks;
|
||
using PhxhSDK;
|
||
using UnityEngine;
|
||
// public enum EPlayType
|
||
// {
|
||
// Music,
|
||
// Sound,
|
||
// Speak
|
||
// }
|
||
|
||
public class AudioManager: Singlenton<AudioManager>, IStart, IInitable, IUpdatable, IAudioPlay
|
||
{
|
||
private AudioUnityManager _audioMgrObj = new();
|
||
//private AudioCriwareManager _audioMgrOldObj = new();
|
||
|
||
public GameObject initGameObject;
|
||
|
||
public static bool DisableAudio = false;
|
||
|
||
private bool isPlayingAlbum = false;
|
||
public bool IsPlayingAlbum
|
||
{
|
||
get
|
||
{
|
||
return isPlayingAlbum;
|
||
}
|
||
set
|
||
{
|
||
isPlayingAlbum = value;
|
||
}
|
||
}
|
||
public bool IsPlayingBGM { get; set; }
|
||
|
||
public AudioUnityManager AudioMgrObj
|
||
{
|
||
get { return _audioMgrObj; }
|
||
}
|
||
|
||
// public AudioCriwareManager AudioOldMgrObj
|
||
// {
|
||
// get { return _audioMgrOldObj; }
|
||
// }
|
||
|
||
private void AfterSwitchCamera(bool isRegister = true)
|
||
{
|
||
if (isRegister)
|
||
{
|
||
CameraManager.Instance.AfterSwitchMainCamera += _audioMgrObj.AfterSwitchMainCamera;
|
||
}
|
||
else
|
||
{
|
||
CameraManager.Instance.AfterSwitchMainCamera -= _audioMgrObj.AfterSwitchMainCamera;
|
||
}
|
||
|
||
}
|
||
|
||
public void Init()
|
||
{
|
||
_audioMgrObj.Init();
|
||
AfterSwitchCamera();
|
||
}
|
||
|
||
public void Release()
|
||
{
|
||
_audioMgrObj.Release();
|
||
AfterSwitchCamera(false);
|
||
}
|
||
|
||
public void Start()
|
||
{
|
||
_audioMgrObj.Start();
|
||
initGameObject = initGameObject;
|
||
}
|
||
|
||
public void Update(float dt)
|
||
{
|
||
_audioMgrObj.Update(dt);
|
||
}
|
||
public float GlobalVolume
|
||
{
|
||
get { return _audioMgrObj.GlobalVolume; }
|
||
set { _audioMgrObj.GlobalVolume = value; }
|
||
}
|
||
|
||
public float GlobalMusicVolume
|
||
{
|
||
get { return _audioMgrObj.GlobalMusicVolume; }
|
||
set { _audioMgrObj.GlobalMusicVolume = value; }
|
||
}
|
||
|
||
public float GlobalSoundsVolume
|
||
{
|
||
get { return _audioMgrObj.GlobalSoundsVolume; }
|
||
set { _audioMgrObj.GlobalSoundsVolume = value; }
|
||
}
|
||
|
||
public bool GlobalIsSpeakOpen
|
||
{
|
||
get { return _audioMgrObj.GlobalIsOpenSpeak; }
|
||
set { _audioMgrObj.GlobalIsOpenSpeak = value; }
|
||
}
|
||
|
||
public float GlobalSpeakVolume
|
||
{
|
||
get { return _audioMgrObj.GlobalSpeakVolume; }
|
||
set { _audioMgrObj.GlobalSpeakVolume = value; }
|
||
}
|
||
|
||
public void SetMusicEnable(bool isEnable)
|
||
{
|
||
GlobalMusicVolume = isEnable ? 1 : 0;
|
||
}
|
||
|
||
public void SetSoundEnable(bool isEnable)
|
||
{
|
||
GlobalSoundsVolume = isEnable ? 1 : 0;
|
||
}
|
||
|
||
// public CriAtomExAcb GetAcb(string cueSheetName)
|
||
// {
|
||
// return _audioMgrObj.GetAcb(cueSheetName);
|
||
// }
|
||
|
||
public async UniTask<float> GetClipLength(string key)
|
||
{
|
||
return await _audioMgrObj.GetClipLength(key);
|
||
}
|
||
|
||
#region 流式播放
|
||
|
||
public int PlayAudio(string key, AudioCriManager.EPlayType type = AudioCriManager.EPlayType.Sound,
|
||
GameObject posObj = null, bool loop = false, bool isFade = false)
|
||
{
|
||
if (type == AudioCriManager.EPlayType.Music)
|
||
{
|
||
//如果使用单个audio播放music,可能会顶掉原先播放的专辑音乐
|
||
//在这里将专辑音乐标记为false
|
||
IsPlayingAlbum = false;
|
||
IsPlayingBGM = false;
|
||
}
|
||
return _audioMgrObj.PlayAudio(key, type, posObj, loop, isFade);
|
||
}
|
||
|
||
public int PlayAudio(string key, Vector3 pos, AudioCriManager.EPlayType type = AudioCriManager.EPlayType.Sound, bool loop = false,
|
||
bool isFade = false)
|
||
{
|
||
if (type == AudioCriManager.EPlayType.Music)
|
||
{
|
||
//如果使用单个audio播放music,可能会顶掉原先播放的专辑音乐
|
||
//在这里将专辑音乐标记为false
|
||
IsPlayingAlbum = false;
|
||
IsPlayingBGM = false;
|
||
}
|
||
return _audioMgrObj.PlayAudio(key, type, pos, loop, isFade);
|
||
}
|
||
|
||
#endregion
|
||
public async UniTask<int> PlayAudioOld(string key, AudioCriManager.EPlayType type = AudioCriManager.EPlayType.Sound, GameObject posObj = null)
|
||
{
|
||
// if (DisableAudio) return 0;
|
||
// return await _audioMgrObj.PlayAudio(key, type, posObj);
|
||
DebugUtil.Log("更换流式播放后,Key值需要修改为String,详情参考AudioSourceConfig");
|
||
return -1;
|
||
}
|
||
|
||
public async UniTask<int> PlayAudioOld(string key, Vector3 pos, AudioCriManager.EPlayType type = AudioCriManager.EPlayType.Sound)
|
||
{
|
||
DebugUtil.Log("更换流式播放后,Key值需要修改为String,详情参考AudioSourceConfig");
|
||
return -1;
|
||
// if (DisableAudio) return 0;
|
||
// return await _audioMgrObj.PlayAudio(key, type, pos);
|
||
}
|
||
|
||
public async UniTask<int> PlayAudioOld(int id, AudioCriManager.EPlayType type = AudioCriManager.EPlayType.Sound, GameObject posObj = null)
|
||
{
|
||
// if (DisableAudio) return 0;
|
||
// return await _audioMgrOldObj.PlayAudio(id, type, posObj);
|
||
DebugUtil.Log("更换流式播放后,Key值需要修改为String,详情参考AudioSourceConfig");
|
||
return -1;
|
||
}
|
||
|
||
public async UniTask<int> PlayAudioOld(int id, Vector3 pos, AudioCriManager.EPlayType type = AudioCriManager.EPlayType.Sound)
|
||
{
|
||
// if (DisableAudio) return 0;
|
||
// DebugUtil.Log("Test");
|
||
// return await _audioMgrOldObj.PlayAudio(id, type, pos);
|
||
DebugUtil.Log("更换流式播放后,Key值需要修改为String,详情参考AudioSourceConfig");
|
||
return -1;
|
||
}
|
||
|
||
public void StopByID(int id)
|
||
{
|
||
if (DisableAudio) return;
|
||
_audioMgrObj.StopByID(id);
|
||
}
|
||
|
||
public void StopWithFadeByID(int id, float fadeOutTime = 1f)
|
||
{
|
||
if (DisableAudio) return;
|
||
_audioMgrObj.StopWithFadeByID(id, fadeOutTime);
|
||
}
|
||
|
||
public void StopMusicById(int id)
|
||
{
|
||
if (DisableAudio) return;
|
||
_audioMgrObj.StopMusicById(id);
|
||
}
|
||
|
||
public void StopSoundById(int id)
|
||
{
|
||
if (DisableAudio) return;
|
||
_audioMgrObj.StopSoundByID(id);
|
||
}
|
||
|
||
public void PauseBackgroundMusic()
|
||
{
|
||
//TODO 暂停背景音乐
|
||
_audioMgrObj?.StopAllMusic();
|
||
}
|
||
public void ResumeBackgroundMusic()
|
||
{
|
||
//TODO 恢复背景音乐
|
||
_audioMgrObj?.ResumeAllMusic();
|
||
}
|
||
// /// <summary>
|
||
// /// 注册音频分析器的对音频挂接的监听
|
||
// /// </summary>
|
||
// /// <returns></returns>
|
||
// public CriAtomExOutputAnalyzer RegisterAnalyzer()//CriAtomExOutputAnalyzer criAtomExOutputAnalyzer
|
||
// {
|
||
// if (DisableAudio) return null;
|
||
// return _audioMgrObj.RegisterAnalyzer();//criAtomExOutputAnalyzer
|
||
// }
|
||
// /// <summary>
|
||
// /// 取消音频分析器对挂接的监听
|
||
// /// </summary>
|
||
// public void UnregisterAnalyzer()//CriAtomExOutputAnalyzer criAtomExOutputAnalyzer
|
||
// {
|
||
// if (DisableAudio) return;
|
||
// _audioMgrObj.UnregisterAnalyzer();//criAtomExOutputAnalyzer
|
||
// }
|
||
// public CriAtomExOutputAnalyzer GetAnalyzer()
|
||
// {
|
||
// return _audioMgrObj.analyzer;
|
||
// }
|
||
|
||
public void StopAllSpeaks()
|
||
{
|
||
_audioMgrObj?.StopAllSpeaks();
|
||
}
|
||
|
||
public void StopAllMusic()
|
||
{
|
||
IsPlayingAlbum = false;
|
||
IsPlayingBGM = false;
|
||
_audioMgrObj?.StopAllMusic();
|
||
}
|
||
|
||
public void StopAll()
|
||
{
|
||
IsPlayingAlbum = false;
|
||
IsPlayingBGM = false;
|
||
_audioMgrObj.StopAll();
|
||
}
|
||
|
||
// public Audio GetAudioByID(AudioType audioType, int id)
|
||
// {
|
||
// if (DisableAudio) return null;
|
||
// return _audioMgrObj.GetAudioByID(audioType, id);
|
||
// }
|
||
|
||
public AudioInst GetAudioByID(AudioCriManager.EPlayType audioType, int id)
|
||
{
|
||
if (DisableAudio) return null;
|
||
return _audioMgrObj.GetAudioByID(audioType, id);
|
||
}
|
||
|
||
public AudioInst GetStoryAudioInst()
|
||
{
|
||
return _audioMgrObj.GetStoryAudioInst();
|
||
}
|
||
|
||
public void ReleaseStoryAudios()
|
||
{
|
||
_audioMgrObj.ReleaseStoryAudios();
|
||
}
|
||
|
||
public void PlayByCueName(int audioID, string cueName, bool isFade = false)
|
||
{
|
||
_audioMgrObj.PlayByCueName(audioID, cueName, isFade);
|
||
}
|
||
|
||
public void PlayByCueName(int audioID, string cueName, float fadeInTime)
|
||
{
|
||
_audioMgrObj.PlayByCueName(audioID, cueName, true, fadeInTime);
|
||
}
|
||
|
||
public void PlayByCueName(int audioID, string cueName, float fadeInTime, float targetVolume)
|
||
{
|
||
_audioMgrObj.PlayByCueName(audioID, cueName, fadeInTime, targetVolume);
|
||
}
|
||
|
||
public int PlayByCueName(string cueName, bool isFade = false, float fadeInTime = 4f)
|
||
{
|
||
return _audioMgrObj.PlayAudio(cueName, AudioCriManager.EPlayType.Music, null, true, isFade, fadeInTime);
|
||
}
|
||
public void ReleaseAllAudios()
|
||
{
|
||
_audioMgrObj.ReleaseAllAudios();
|
||
}
|
||
|
||
// public long GetCueLength(string cueSheet, string cueName)
|
||
// {
|
||
// return _audioMgrObj.GetCueLength(cueSheet, cueName);
|
||
// }
|
||
|
||
public void InitLimit(int c0, int c1, int c2)
|
||
{
|
||
AudioMgrObj.InitLimit(c0, c1, c2);
|
||
}
|
||
} |