2024-01-19 17:25:06 +08:00
|
|
|
|
using System;
|
2024-03-26 12:22:47 +08:00
|
|
|
|
using CriWare;
|
|
|
|
|
|
using CriWare.Assets;
|
2024-01-19 17:25:06 +08:00
|
|
|
|
using Cysharp.Threading.Tasks;
|
2023-11-29 15:17:00 +08:00
|
|
|
|
using PhxhSDK;
|
2023-08-22 19:08:45 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
2023-11-29 15:17:00 +08:00
|
|
|
|
public class AudioManager: Singlenton<AudioManager>, IStart, IInitable, IUpdatable, IAudioPlay
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
2024-07-22 19:35:34 +08:00
|
|
|
|
private AudioCriManager _audioMgrObj = new();
|
|
|
|
|
|
private AudioCriwareManager _audioMgrOldObj = new();
|
2023-11-29 15:17:00 +08:00
|
|
|
|
|
2023-08-22 19:08:45 +08:00
|
|
|
|
public GameObject initGameObject;
|
2024-01-19 17:25:06 +08:00
|
|
|
|
|
2024-04-28 17:03:37 +08:00
|
|
|
|
public static bool DisableAudio = false;
|
2024-04-28 16:18:27 +08:00
|
|
|
|
|
2024-07-01 17:23:05 +08:00
|
|
|
|
private bool isPlayingAlbum = false;
|
|
|
|
|
|
public bool IsPlayingAlbum
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return isPlayingAlbum;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
isPlayingAlbum = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-22 19:35:34 +08:00
|
|
|
|
public AudioCriManager AudioMgrObj
|
2024-03-26 12:22:47 +08:00
|
|
|
|
{
|
|
|
|
|
|
get { return _audioMgrObj; }
|
|
|
|
|
|
}
|
2024-07-22 19:35:34 +08:00
|
|
|
|
|
|
|
|
|
|
public AudioCriwareManager AudioOldMgrObj
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return _audioMgrOldObj; }
|
|
|
|
|
|
}
|
2024-03-26 12:22:47 +08:00
|
|
|
|
|
2024-01-19 17:25:06 +08:00
|
|
|
|
private void AfterSwitchCamera(bool isRegister = true)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (isRegister)
|
|
|
|
|
|
{
|
|
|
|
|
|
CameraManager.Instance.AfterSwitchMainCamera += _audioMgrObj.AfterSwitchMainCamera;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
CameraManager.Instance.AfterSwitchMainCamera -= _audioMgrObj.AfterSwitchMainCamera;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-22 19:08:45 +08:00
|
|
|
|
public void Init()
|
|
|
|
|
|
{
|
2023-11-29 15:17:00 +08:00
|
|
|
|
_audioMgrObj.Init();
|
2024-01-19 17:25:06 +08:00
|
|
|
|
AfterSwitchCamera();
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
2023-11-29 15:17:00 +08:00
|
|
|
|
|
2023-08-22 19:08:45 +08:00
|
|
|
|
public void Release()
|
|
|
|
|
|
{
|
2023-11-29 15:17:00 +08:00
|
|
|
|
_audioMgrObj.Release();
|
2024-01-19 17:25:06 +08:00
|
|
|
|
AfterSwitchCamera(false);
|
2023-10-19 15:00:19 +08:00
|
|
|
|
}
|
2023-11-29 15:17:00 +08:00
|
|
|
|
|
|
|
|
|
|
public void Start()
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
2023-11-29 15:17:00 +08:00
|
|
|
|
_audioMgrObj.Start();
|
2024-07-22 19:35:34 +08:00
|
|
|
|
initGameObject = initGameObject;
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
2023-11-29 15:17:00 +08:00
|
|
|
|
|
|
|
|
|
|
public void Update(float dt)
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
2023-11-29 15:17:00 +08:00
|
|
|
|
_audioMgrObj.Update(dt);
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
2023-11-29 15:17:00 +08:00
|
|
|
|
public float GlobalVolume
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
2023-11-29 15:17:00 +08:00
|
|
|
|
get { return _audioMgrObj.GlobalVolume; }
|
|
|
|
|
|
set { _audioMgrObj.GlobalVolume = value; }
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-29 15:17:00 +08:00
|
|
|
|
public float GlobalMusicVolume
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
2023-11-29 15:17:00 +08:00
|
|
|
|
get { return _audioMgrObj.GlobalMusicVolume; }
|
|
|
|
|
|
set { _audioMgrObj.GlobalMusicVolume = value; }
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-29 15:17:00 +08:00
|
|
|
|
public float GlobalSoundsVolume
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
2023-11-29 15:17:00 +08:00
|
|
|
|
get { return _audioMgrObj.GlobalSoundsVolume; }
|
|
|
|
|
|
set { _audioMgrObj.GlobalSoundsVolume = value; }
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
2023-12-13 15:14:52 +08:00
|
|
|
|
|
|
|
|
|
|
public bool GlobalIsSpeakOpen
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return _audioMgrObj.GlobalIsOpenSpeak; }
|
|
|
|
|
|
set { _audioMgrObj.GlobalIsOpenSpeak = value; }
|
|
|
|
|
|
}
|
2024-04-28 14:24:10 +08:00
|
|
|
|
|
|
|
|
|
|
public float GlobalSpeakVolume
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return _audioMgrObj.GlobalSpeakVolume; }
|
|
|
|
|
|
set { _audioMgrObj.GlobalSpeakVolume = value; }
|
|
|
|
|
|
}
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2023-08-22 19:08:45 +08:00
|
|
|
|
public void SetMusicEnable(bool isEnable)
|
|
|
|
|
|
{
|
|
|
|
|
|
GlobalMusicVolume = isEnable ? 1 : 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SetSoundEnable(bool isEnable)
|
|
|
|
|
|
{
|
|
|
|
|
|
GlobalSoundsVolume = isEnable ? 1 : 0;
|
|
|
|
|
|
}
|
2024-07-22 19:35:34 +08:00
|
|
|
|
|
|
|
|
|
|
public CriAtomExAcb GetAcb(string cueSheetName)
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
2024-07-22 19:35:34 +08:00
|
|
|
|
return _audioMgrObj.GetAcb(cueSheetName);
|
2023-10-19 15:00:19 +08:00
|
|
|
|
}
|
2024-07-22 19:35:34 +08:00
|
|
|
|
|
|
|
|
|
|
#region 流式播放
|
|
|
|
|
|
|
|
|
|
|
|
public int PlayAudio(string key, AudioCriManager.EPlayType type = AudioCriManager.EPlayType.Sound, GameObject posObj = null)
|
2023-10-19 15:00:19 +08:00
|
|
|
|
{
|
2024-07-24 17:33:23 +08:00
|
|
|
|
return _audioMgrObj.PlayAudio(key, type, posObj);
|
2023-10-19 15:00:19 +08:00
|
|
|
|
}
|
2024-07-25 17:43:14 +08:00
|
|
|
|
|
|
|
|
|
|
public int PlayAudio(string key, Vector3 pos, AudioCriManager.EPlayType type = AudioCriManager.EPlayType.Sound)
|
|
|
|
|
|
{
|
|
|
|
|
|
return _audioMgrObj.PlayAudio(key, type, pos);
|
|
|
|
|
|
}
|
2024-07-22 19:35:34 +08:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
2024-07-25 16:23:17 +08:00
|
|
|
|
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);
|
|
|
|
|
|
Debug.Log("更换流式播放后,Key值需要修改为String,详情参考AudioSourceConfig");
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2024-07-25 16:23:17 +08:00
|
|
|
|
public async UniTask<int> PlayAudioOld(string key, Vector3 pos, AudioCriManager.EPlayType type = AudioCriManager.EPlayType.Sound)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.Log("更换流式播放后,Key值需要修改为String,详情参考AudioSourceConfig");
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
// if (DisableAudio) return 0;
|
|
|
|
|
|
// return await _audioMgrObj.PlayAudio(key, type, pos);
|
|
|
|
|
|
}
|
2024-07-22 19:35:34 +08:00
|
|
|
|
|
|
|
|
|
|
public async UniTask<int> PlayAudioOld(int id, AudioCriManager.EPlayType type = AudioCriManager.EPlayType.Sound, GameObject posObj = null)
|
2023-10-19 15:00:19 +08:00
|
|
|
|
{
|
2024-07-22 19:35:34 +08:00
|
|
|
|
// if (DisableAudio) return 0;
|
|
|
|
|
|
// return await _audioMgrOldObj.PlayAudio(id, type, posObj);
|
|
|
|
|
|
Debug.Log("更换流式播放后,Key值需要修改为String,详情参考AudioSourceConfig");
|
|
|
|
|
|
return -1;
|
2023-10-24 18:53:34 +08:00
|
|
|
|
}
|
2023-11-29 15:17:00 +08:00
|
|
|
|
|
2024-07-22 19:35:34 +08:00
|
|
|
|
public async UniTask<int> PlayAudioOld(int id, Vector3 pos, AudioCriManager.EPlayType type = AudioCriManager.EPlayType.Sound)
|
2023-10-19 15:00:19 +08:00
|
|
|
|
{
|
2024-07-22 19:35:34 +08:00
|
|
|
|
// if (DisableAudio) return 0;
|
|
|
|
|
|
// DebugUtil.Log("Test");
|
|
|
|
|
|
// return await _audioMgrOldObj.PlayAudio(id, type, pos);
|
|
|
|
|
|
Debug.Log("更换流式播放后,Key值需要修改为String,详情参考AudioSourceConfig");
|
|
|
|
|
|
return -1;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
}
|
2024-03-26 12:22:47 +08:00
|
|
|
|
|
2024-04-24 12:59:23 +08:00
|
|
|
|
public void StopMusicById(int id)
|
|
|
|
|
|
{
|
2024-04-28 16:18:27 +08:00
|
|
|
|
if (DisableAudio) return;
|
2024-04-24 12:59:23 +08:00
|
|
|
|
_audioMgrObj.StopMusicById(id);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-01 17:23:05 +08:00
|
|
|
|
public void PauseBackgroundMusic()
|
|
|
|
|
|
{
|
|
|
|
|
|
//TODO 暂停背景音乐
|
|
|
|
|
|
_audioMgrObj?.StopAllMusic();
|
|
|
|
|
|
}
|
|
|
|
|
|
public void ResumeBackgroundMusic()
|
|
|
|
|
|
{
|
|
|
|
|
|
//TODO 恢复背景音乐
|
|
|
|
|
|
_audioMgrObj?.ResumeAllMusic();
|
|
|
|
|
|
}
|
2024-07-11 17:20:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 注册音频分析器的对音频挂接的监听
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public CriAtomExOutputAnalyzer RegisterAnalyzer()//CriAtomExOutputAnalyzer criAtomExOutputAnalyzer
|
2024-03-26 12:22:47 +08:00
|
|
|
|
{
|
2024-07-11 17:20:52 +08:00
|
|
|
|
if (DisableAudio) return null;
|
|
|
|
|
|
return _audioMgrObj.RegisterAnalyzer();//criAtomExOutputAnalyzer
|
2024-03-26 12:22:47 +08:00
|
|
|
|
}
|
2024-07-11 17:20:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 取消音频分析器对挂接的监听
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void UnregisterAnalyzer()//CriAtomExOutputAnalyzer criAtomExOutputAnalyzer
|
2024-03-26 12:22:47 +08:00
|
|
|
|
{
|
2024-04-28 16:18:27 +08:00
|
|
|
|
if (DisableAudio) return;
|
2024-07-11 17:20:52 +08:00
|
|
|
|
_audioMgrObj.UnregisterAnalyzer();//criAtomExOutputAnalyzer
|
2024-03-26 12:22:47 +08:00
|
|
|
|
}
|
2024-07-08 19:56:16 +08:00
|
|
|
|
public CriAtomExOutputAnalyzer GetAnalyzer()
|
|
|
|
|
|
{
|
|
|
|
|
|
return _audioMgrObj.analyzer;
|
|
|
|
|
|
}
|
2024-04-11 19:15:37 +08:00
|
|
|
|
|
|
|
|
|
|
public void StopAll()
|
|
|
|
|
|
{
|
|
|
|
|
|
_audioMgrObj.StopAll();
|
|
|
|
|
|
}
|
2024-04-23 19:42:31 +08:00
|
|
|
|
|
2024-07-22 19:35:34 +08:00
|
|
|
|
// public Audio GetAudioByID(AudioType audioType, int id)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// if (DisableAudio) return null;
|
|
|
|
|
|
// return _audioMgrObj.GetAudioByID(audioType, id);
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
public AudioInst GetAudioByID(AudioCriManager.EPlayType audioType, int id)
|
2024-04-23 19:42:31 +08:00
|
|
|
|
{
|
2024-04-28 16:18:27 +08:00
|
|
|
|
if (DisableAudio) return null;
|
2024-04-23 19:42:31 +08:00
|
|
|
|
return _audioMgrObj.GetAudioByID(audioType, id);
|
|
|
|
|
|
}
|
2024-08-01 14:03:20 +08:00
|
|
|
|
|
|
|
|
|
|
public AudioInst GetStoryAudioInst()
|
|
|
|
|
|
{
|
|
|
|
|
|
return _audioMgrObj.GetStoryAudioInst();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void ReleaseStoryAudios()
|
|
|
|
|
|
{
|
|
|
|
|
|
_audioMgrObj.ReleaseStoryAudios();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void PlayByCueName(int audioID, string cueName)
|
|
|
|
|
|
{
|
|
|
|
|
|
_audioMgrObj.PlayByCueName(audioID, cueName);
|
|
|
|
|
|
}
|
2023-11-29 15:17:00 +08:00
|
|
|
|
}
|