2024-07-17 13:59:24 +08:00
|
|
|
|
//流式播放的音频管理器
|
2024-09-04 16:02:38 +08:00
|
|
|
|
|
|
|
|
|
|
using System;
|
2024-07-17 13:59:24 +08:00
|
|
|
|
using System.Collections.Generic;
|
2024-08-23 19:53:32 +08:00
|
|
|
|
using System.Linq;
|
2024-10-16 16:03:13 +08:00
|
|
|
|
using cfg.DeviceCfg;
|
2024-07-17 13:59:24 +08:00
|
|
|
|
using CriWare;
|
|
|
|
|
|
using Framework;
|
|
|
|
|
|
using PhxhSDK;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using AudioType = PhxhSDK.AudioBase.AudioType;
|
2024-09-04 16:02:38 +08:00
|
|
|
|
using Object = UnityEngine.Object;
|
2024-07-17 13:59:24 +08:00
|
|
|
|
|
|
|
|
|
|
public class AudioCriManager: Singlenton<AudioCriManager>, IStart, IInitable, IUpdatable, IAudioPlay
|
|
|
|
|
|
{
|
2024-07-22 19:35:34 +08:00
|
|
|
|
public GameObject initGameObject;
|
2024-07-17 13:59:24 +08:00
|
|
|
|
public GameObject AudioRoot;
|
|
|
|
|
|
public GameObject CriAtomRoot;
|
|
|
|
|
|
public CriAtom CriAtom;
|
|
|
|
|
|
public ClipType curClipType;
|
2024-07-22 19:35:34 +08:00
|
|
|
|
|
|
|
|
|
|
private AudioInst _bgmAudio;
|
2024-10-28 19:11:12 +08:00
|
|
|
|
public CriAtomListener Listener;
|
|
|
|
|
|
private Dictionary<string, CriAtomEx.CueInfo[]> _cacheCueInfoArrays = new();
|
2024-10-16 15:18:33 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 对象池数量限制
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public int MusicPoolLimit = 1;
|
|
|
|
|
|
public int SoundPoolLimit = 100;
|
|
|
|
|
|
public int SpeakPoolLimit = 1;
|
2024-07-17 13:59:24 +08:00
|
|
|
|
|
|
|
|
|
|
public enum EPlayType
|
|
|
|
|
|
{
|
|
|
|
|
|
Music,
|
|
|
|
|
|
Sound,
|
|
|
|
|
|
Speak
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private GameObject _criError;
|
|
|
|
|
|
|
|
|
|
|
|
private Dictionary<int, AudioInst> _soundAudioDic;
|
2024-10-12 18:21:33 +08:00
|
|
|
|
private Dictionary<int, AudioInst> _soundAudioLoopDic;
|
2024-07-17 13:59:24 +08:00
|
|
|
|
private Dictionary<int, AudioInst> _musicAudioDic;
|
2024-10-12 18:21:33 +08:00
|
|
|
|
private Dictionary<int, AudioInst> _musicAudioLoopDic;
|
2024-07-17 13:59:24 +08:00
|
|
|
|
private Dictionary<int, AudioInst> _allAudioDic;
|
2024-10-12 18:21:33 +08:00
|
|
|
|
|
2024-07-17 13:59:24 +08:00
|
|
|
|
private List<GameObject> _soundAudioObj;
|
2024-10-12 18:21:33 +08:00
|
|
|
|
private List<GameObject> _soundAudioLoopObj;
|
2024-07-17 13:59:24 +08:00
|
|
|
|
private List<GameObject> _musicAudioObj;
|
2024-10-12 18:21:33 +08:00
|
|
|
|
private List<GameObject> _musicAudioLoopObj;
|
2024-10-16 15:18:33 +08:00
|
|
|
|
|
|
|
|
|
|
public enum PlayType
|
|
|
|
|
|
{
|
|
|
|
|
|
Music,
|
|
|
|
|
|
Sound,
|
|
|
|
|
|
Speak
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Dictionary<PlayType, List<int>> _playingLDic;
|
|
|
|
|
|
|
2024-07-17 13:59:24 +08:00
|
|
|
|
private List<AudioInst> _soundAudioQue;
|
|
|
|
|
|
|
2024-08-01 14:03:20 +08:00
|
|
|
|
private Dictionary<int, AudioInst> _storyAudioDic;
|
|
|
|
|
|
|
2024-07-17 13:59:24 +08:00
|
|
|
|
private const int SOUND_MAX_NUM = 20;
|
|
|
|
|
|
private const int MUSIC_MAX_NUM = 2;
|
|
|
|
|
|
|
|
|
|
|
|
#region Property
|
|
|
|
|
|
|
2024-07-22 19:35:34 +08:00
|
|
|
|
private float _vol = 1f;
|
|
|
|
|
|
|
|
|
|
|
|
public float GlobalSoundsVolume
|
|
|
|
|
|
{
|
|
|
|
|
|
get => AudioCri.GlobalSoundVolume;
|
|
|
|
|
|
set => AudioCri.GlobalSoundVolume = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
public float GlobalSpeakVolume{
|
|
|
|
|
|
get => AudioCri.GlobalSpeakVolume;
|
|
|
|
|
|
set => AudioCri.GlobalSpeakVolume = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public float GlobalMusicVolume {
|
|
|
|
|
|
get => AudioCri.GlobalMusicVolume;
|
|
|
|
|
|
set => AudioCri.GlobalMusicVolume = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public float GlobalVolume
|
|
|
|
|
|
{
|
|
|
|
|
|
get => AudioCri.GlobalVolume;
|
|
|
|
|
|
set => AudioCri.GlobalVolume = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool GlobalIsOpenSpeak;
|
|
|
|
|
|
|
2024-10-12 16:36:10 +08:00
|
|
|
|
public AudioInst BgmAudio
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return _bgmAudio; }
|
|
|
|
|
|
set { _bgmAudio = value; }
|
|
|
|
|
|
}
|
2024-07-22 19:35:34 +08:00
|
|
|
|
|
|
|
|
|
|
public CriAtomExOutputAnalyzer analyzer=null;
|
|
|
|
|
|
public bool IsAnalyzer = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Analyze
|
|
|
|
|
|
|
|
|
|
|
|
//在播放之前注册
|
|
|
|
|
|
public CriAtomExOutputAnalyzer RegisterAnalyzer()//CriAtomExOutputAnalyzer s
|
|
|
|
|
|
{
|
|
|
|
|
|
IsAnalyzer = true;
|
|
|
|
|
|
if (analyzer == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
analyzer = new(NewAnalyzerConfig());
|
|
|
|
|
|
}
|
|
|
|
|
|
return analyzer;
|
|
|
|
|
|
//analyzer = s;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void UnregisterAnalyzer()//CriAtomExOutputAnalyzer s
|
|
|
|
|
|
{
|
|
|
|
|
|
//s.DetachExPlayer();
|
|
|
|
|
|
IsAnalyzer = false;
|
|
|
|
|
|
//analyzer = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取音频输出分析器配置
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
private CriAtomExOutputAnalyzer.Config NewAnalyzerConfig()
|
|
|
|
|
|
{
|
|
|
|
|
|
CriAtomExOutputAnalyzer.Config config = new()
|
|
|
|
|
|
{
|
|
|
|
|
|
enableSpectrumAnalyzer = true, // 开启频谱分析
|
|
|
|
|
|
numSpectrumAnalyzerBands = 16, // 频谱分析数量SPECTRUM_SAMPLES_NUMBER
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return config;
|
|
|
|
|
|
}
|
2024-07-17 13:59:24 +08:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Framework
|
|
|
|
|
|
|
|
|
|
|
|
public void Start()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!AudioRoot)
|
|
|
|
|
|
{
|
|
|
|
|
|
curClipType = ClipType.CriwareClip;
|
|
|
|
|
|
|
|
|
|
|
|
AudioRoot = new GameObject();
|
|
|
|
|
|
AudioRoot.name = "Audio(Singleton)";
|
|
|
|
|
|
Object.DontDestroyOnLoad(AudioRoot);
|
2024-07-22 19:35:34 +08:00
|
|
|
|
|
2024-07-17 13:59:24 +08:00
|
|
|
|
if (curClipType == ClipType.CriwareClip)
|
|
|
|
|
|
{
|
|
|
|
|
|
_criError = new GameObject();
|
2024-07-22 19:35:34 +08:00
|
|
|
|
_criError.name = "CriwareError";
|
2024-07-17 13:59:24 +08:00
|
|
|
|
_criError.AddComponent<CriWareErrorHandler>();
|
|
|
|
|
|
Object.DontDestroyOnLoad(_criError);
|
|
|
|
|
|
}
|
2024-07-22 19:35:34 +08:00
|
|
|
|
|
2024-07-24 12:41:45 +08:00
|
|
|
|
var initialize = GameObject.Find("CriWareLibraryInitializer");
|
|
|
|
|
|
Object.DontDestroyOnLoad(initialize);
|
2024-07-17 13:59:24 +08:00
|
|
|
|
CriAtomRoot = GameObject.Find("CriAtom");
|
|
|
|
|
|
CriAtom = CriAtomRoot.GetComponent<CriAtom>();
|
|
|
|
|
|
Object.DontDestroyOnLoad(CriAtomRoot);
|
2024-07-22 19:35:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
// CriAtomRoot = new GameObject()
|
2024-07-17 13:59:24 +08:00
|
|
|
|
// {
|
|
|
|
|
|
// name = "CriAtom"
|
|
|
|
|
|
// };
|
|
|
|
|
|
// CriAtom = CriAtomRoot.AddComponent<CriAtom>();
|
|
|
|
|
|
// CriAtom.AddCueSheet()
|
|
|
|
|
|
|
|
|
|
|
|
// for (int i = 0; i < SOUND_MAX_NUM; i++)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// var go = new GameObject
|
|
|
|
|
|
// {
|
|
|
|
|
|
// name = "Sound" + (i+1)
|
|
|
|
|
|
// };
|
|
|
|
|
|
// go.transform.SetParent(AudioRoot.transform);
|
|
|
|
|
|
// }
|
|
|
|
|
|
//
|
|
|
|
|
|
// for (int i = 0; i < MUSIC_MAX_NUM; i++)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// var go = new GameObject
|
|
|
|
|
|
// {
|
|
|
|
|
|
// name = "Music" + (i+1)
|
|
|
|
|
|
// };
|
|
|
|
|
|
// go.transform.SetParent(AudioRoot.transform);
|
|
|
|
|
|
// }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Init()
|
|
|
|
|
|
{
|
2024-07-22 19:35:34 +08:00
|
|
|
|
_soundAudioDic = new Dictionary<int, AudioInst>();
|
2024-10-12 18:21:33 +08:00
|
|
|
|
_soundAudioLoopDic = new Dictionary<int, AudioInst>();
|
2024-07-22 19:35:34 +08:00
|
|
|
|
_musicAudioDic = new Dictionary<int, AudioInst>();
|
2024-10-12 18:21:33 +08:00
|
|
|
|
_musicAudioLoopDic = new Dictionary<int, AudioInst>();
|
|
|
|
|
|
|
2024-07-22 19:35:34 +08:00
|
|
|
|
_allAudioDic = new Dictionary<int, AudioInst>();
|
2024-10-12 18:21:33 +08:00
|
|
|
|
_soundAudioLoopObj = new();
|
|
|
|
|
|
_musicAudioLoopObj = new();
|
2024-07-22 19:35:34 +08:00
|
|
|
|
_soundAudioObj = new();
|
|
|
|
|
|
_musicAudioObj = new();
|
2024-10-16 15:18:33 +08:00
|
|
|
|
_playingLDic = new ();
|
|
|
|
|
|
_playingLDic.Add(PlayType.Music, new List<int>());
|
|
|
|
|
|
_playingLDic.Add(PlayType.Sound, new List<int>());
|
|
|
|
|
|
_playingLDic.Add(PlayType.Speak, new List<int>());
|
2024-10-12 18:21:33 +08:00
|
|
|
|
|
2024-08-01 14:03:20 +08:00
|
|
|
|
_storyAudioDic = new();
|
2024-07-17 13:59:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Release()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Update(float dt)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var kv in _musicAudioDic)
|
|
|
|
|
|
{
|
|
|
|
|
|
var audio = kv.Value;
|
|
|
|
|
|
if (!audio.IsStopped)
|
|
|
|
|
|
{
|
2024-09-10 14:56:42 +08:00
|
|
|
|
audio.Update(dt);
|
2024-07-17 13:59:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-12 18:21:33 +08:00
|
|
|
|
foreach (var kv in _musicAudioLoopDic)
|
|
|
|
|
|
{
|
|
|
|
|
|
var audio = kv.Value;
|
|
|
|
|
|
if (!audio.IsStopped)
|
|
|
|
|
|
{
|
|
|
|
|
|
audio.Update(dt);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-17 13:59:24 +08:00
|
|
|
|
foreach (var kv in _soundAudioDic)
|
|
|
|
|
|
{
|
|
|
|
|
|
var audio = kv.Value;
|
|
|
|
|
|
if (!audio.IsStopped)
|
|
|
|
|
|
{
|
2024-09-10 14:56:42 +08:00
|
|
|
|
audio.Update(dt);
|
2024-07-17 13:59:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-10-12 18:21:33 +08:00
|
|
|
|
|
|
|
|
|
|
foreach (var kv in _soundAudioLoopDic)
|
|
|
|
|
|
{
|
|
|
|
|
|
var audio = kv.Value;
|
|
|
|
|
|
if (!audio.IsStopped)
|
|
|
|
|
|
{
|
|
|
|
|
|
audio.Update(dt);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-08-01 14:03:20 +08:00
|
|
|
|
|
|
|
|
|
|
foreach (var kv in _storyAudioDic)
|
|
|
|
|
|
{
|
|
|
|
|
|
var audio = kv.Value;
|
|
|
|
|
|
if (!audio.IsStopped)
|
|
|
|
|
|
{
|
2024-09-10 14:56:42 +08:00
|
|
|
|
audio.Update(dt);
|
2024-08-01 14:03:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-07-17 13:59:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region LoadAsset
|
|
|
|
|
|
|
2024-10-28 19:11:12 +08:00
|
|
|
|
// private string _GetCriPath(string name)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// var commonStr = "CueSheet_";
|
|
|
|
|
|
// var strArr = name.Split('_');
|
|
|
|
|
|
// var pre = strArr[0];
|
|
|
|
|
|
// if (pre != null)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// if (pre == "Voice")
|
|
|
|
|
|
// {
|
|
|
|
|
|
// return "CueSheet_Voice";
|
|
|
|
|
|
// }
|
|
|
|
|
|
//
|
|
|
|
|
|
// if (pre == "bgm")
|
|
|
|
|
|
// {
|
|
|
|
|
|
// return "CueSheet_bgm";
|
|
|
|
|
|
// }
|
|
|
|
|
|
//
|
|
|
|
|
|
// if (pre == "Sound")
|
|
|
|
|
|
// {
|
|
|
|
|
|
// return "CueSheet_Sound";
|
|
|
|
|
|
// }
|
|
|
|
|
|
//
|
|
|
|
|
|
// if (pre == "ev")
|
|
|
|
|
|
// {
|
|
|
|
|
|
// return "CueSheet_ev";
|
|
|
|
|
|
// }
|
|
|
|
|
|
//
|
|
|
|
|
|
// if (pre == "ui")
|
|
|
|
|
|
// {
|
|
|
|
|
|
// return "CueSheet_ui";
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
//
|
|
|
|
|
|
// return "";
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
//优化SplitGC
|
2024-07-22 19:35:34 +08:00
|
|
|
|
private string _GetCriPath(string name)
|
2024-07-17 13:59:24 +08:00
|
|
|
|
{
|
2024-10-28 19:11:12 +08:00
|
|
|
|
var firstChar = name[0];
|
|
|
|
|
|
if (!string.IsNullOrEmpty(name))
|
2024-07-22 19:35:34 +08:00
|
|
|
|
{
|
2024-10-28 19:11:12 +08:00
|
|
|
|
if (firstChar == 'b')
|
2024-07-22 19:35:34 +08:00
|
|
|
|
{
|
2024-10-28 19:11:12 +08:00
|
|
|
|
return "CueSheet_bgm";
|
2024-07-22 19:35:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-28 19:11:12 +08:00
|
|
|
|
if (firstChar == 'V')
|
2024-07-22 19:35:34 +08:00
|
|
|
|
{
|
2024-10-28 19:11:12 +08:00
|
|
|
|
return "CueSheet_Voice";
|
2024-07-22 19:35:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-28 19:11:12 +08:00
|
|
|
|
if (firstChar == 'S')
|
2024-07-25 17:43:14 +08:00
|
|
|
|
{
|
|
|
|
|
|
return "CueSheet_Sound";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-28 19:11:12 +08:00
|
|
|
|
if (firstChar == 'e')
|
2024-07-22 19:35:34 +08:00
|
|
|
|
{
|
2024-07-25 17:43:14 +08:00
|
|
|
|
return "CueSheet_ev";
|
2024-07-22 19:35:34 +08:00
|
|
|
|
}
|
2024-09-30 19:47:48 +08:00
|
|
|
|
|
2024-10-28 19:11:12 +08:00
|
|
|
|
if (firstChar == 'u')
|
2024-09-30 19:47:48 +08:00
|
|
|
|
{
|
|
|
|
|
|
return "CueSheet_ui";
|
|
|
|
|
|
}
|
2024-07-22 19:35:34 +08:00
|
|
|
|
}
|
2024-07-17 13:59:24 +08:00
|
|
|
|
|
2024-09-18 12:07:22 +08:00
|
|
|
|
return "";
|
2024-07-22 19:35:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private string _GetAcbPath(string name)
|
|
|
|
|
|
{
|
|
|
|
|
|
var path = _GetCriPath(name);
|
2024-09-18 12:07:22 +08:00
|
|
|
|
if (string.IsNullOrEmpty(path))
|
2024-07-22 19:35:34 +08:00
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogError($"获取不到对应的ACB文件,key: {name}");
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return path + ".acb";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private string _GetAwbPath(string name)
|
|
|
|
|
|
{
|
|
|
|
|
|
var path = _GetCriPath(name);
|
2024-09-18 12:07:22 +08:00
|
|
|
|
if (string.IsNullOrEmpty(path))
|
2024-07-22 19:35:34 +08:00
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogError($"获取不到对应的AWB文件,key: {name}");
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return path + ".awb";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private string _GetAcfPath(string name)
|
|
|
|
|
|
{
|
|
|
|
|
|
var path = _GetCriPath(name);
|
|
|
|
|
|
if (path == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogError($"获取不到对应的ACF文件,key: {name}");
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return path + ".acf";
|
2024-07-17 13:59:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region AudioObj
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取可用的Audio
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="audioType"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2024-10-16 15:18:33 +08:00
|
|
|
|
private AudioInst _GetUsableAudio(AudioBase.AudioType audioType, bool isLoop, bool isSpeak = false)
|
2024-07-17 13:59:24 +08:00
|
|
|
|
{
|
2024-11-06 15:24:33 +08:00
|
|
|
|
try
|
2024-10-16 15:18:33 +08:00
|
|
|
|
{
|
2024-11-06 15:24:33 +08:00
|
|
|
|
var limit = _CheckIsAudioLimited(audioType, isSpeak);
|
|
|
|
|
|
if (limit)
|
|
|
|
|
|
{
|
|
|
|
|
|
return _GetOldAudio(audioType, isLoop, isSpeak);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var freeAudio = _GetFreeAudio(audioType, isLoop);
|
|
|
|
|
|
return freeAudio ?? _CreateNewAudio(audioType, isLoop);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogError($"AudioManger, GetUsableAudio Fail.");
|
2024-10-16 15:18:33 +08:00
|
|
|
|
}
|
2024-11-06 15:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
return null;
|
2024-07-17 13:59:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-16 15:18:33 +08:00
|
|
|
|
private AudioInst _GetOldAudio(AudioBase.AudioType audioType, bool isLoop, bool isSpeak)
|
|
|
|
|
|
{
|
|
|
|
|
|
var playingList = _playingLDic[GetPlayType(audioType, isSpeak)];
|
|
|
|
|
|
if (playingList.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
var audio = GetAudioByID(playingList[0]);
|
|
|
|
|
|
return audio;
|
|
|
|
|
|
}
|
|
|
|
|
|
return _CreateNewAudio(audioType, isLoop);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private int _GetLimit(AudioBase.AudioType audioType, bool isSpeak)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (isSpeak)
|
|
|
|
|
|
{
|
|
|
|
|
|
return SpeakPoolLimit;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (audioType == AudioBase.AudioType.Music)
|
|
|
|
|
|
{
|
|
|
|
|
|
return MusicPoolLimit;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (audioType == AudioBase.AudioType.Sound)
|
|
|
|
|
|
{
|
|
|
|
|
|
return SoundPoolLimit;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private PlayType GetPlayType(AudioBase.AudioType audioType, bool isSpeak)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (isSpeak)
|
|
|
|
|
|
return PlayType.Speak;
|
|
|
|
|
|
if (audioType == AudioBase.AudioType.Music)
|
|
|
|
|
|
return PlayType.Music;
|
|
|
|
|
|
return PlayType.Sound;
|
|
|
|
|
|
}
|
|
|
|
|
|
private bool _CheckIsAudioLimited(AudioBase.AudioType audioType, bool isSpeak)
|
|
|
|
|
|
{
|
|
|
|
|
|
var limit = _GetLimit(audioType, isSpeak);
|
|
|
|
|
|
var playingList = _playingLDic[GetPlayType(audioType, isSpeak)];
|
|
|
|
|
|
if (playingList.Count >= limit)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-12 18:21:33 +08:00
|
|
|
|
private Dictionary<int, AudioInst> _GetAudioDic(AudioBase.AudioType audioType, bool isLoop)
|
2024-07-17 13:59:24 +08:00
|
|
|
|
{
|
|
|
|
|
|
switch (audioType)
|
|
|
|
|
|
{
|
|
|
|
|
|
case AudioBase.AudioType.Music:
|
2024-10-12 18:21:33 +08:00
|
|
|
|
return isLoop? _musicAudioLoopDic : _musicAudioDic;
|
2024-07-17 13:59:24 +08:00
|
|
|
|
case AudioBase.AudioType.Sound:
|
2024-10-12 18:21:33 +08:00
|
|
|
|
return isLoop? _soundAudioLoopDic : _soundAudioDic;
|
2024-07-17 13:59:24 +08:00
|
|
|
|
default:
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogError("获取AudioDic出错!!!传入AudioType有误!");
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-12 18:21:33 +08:00
|
|
|
|
private AudioInst _GetFreeAudio(AudioBase.AudioType audioType, bool isLoop)
|
2024-07-17 13:59:24 +08:00
|
|
|
|
{
|
2024-10-12 18:21:33 +08:00
|
|
|
|
var dic = _GetAudioDic(audioType, isLoop);
|
2024-07-17 13:59:24 +08:00
|
|
|
|
if (dic != null)
|
|
|
|
|
|
{
|
2024-07-22 19:35:34 +08:00
|
|
|
|
foreach (var kv in dic)
|
2024-07-17 13:59:24 +08:00
|
|
|
|
{
|
|
|
|
|
|
var audio = kv.Value;
|
|
|
|
|
|
if (audio.IsStopped)
|
|
|
|
|
|
{
|
|
|
|
|
|
return audio;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2024-08-01 14:03:20 +08:00
|
|
|
|
|
|
|
|
|
|
private AudioInst _CreateStoryAudio(GameObject posGo = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var rootGo = new GameObject()
|
|
|
|
|
|
{
|
|
|
|
|
|
name = "AudioStory"
|
|
|
|
|
|
};
|
|
|
|
|
|
rootGo.transform.SetParent(AudioRoot.transform);
|
|
|
|
|
|
var audio = new AudioInst(AudioBase.AudioType.Sound, rootGo, null);
|
|
|
|
|
|
rootGo.name += audio.audioID;
|
|
|
|
|
|
_storyAudioDic.TryAdd(audio.audioID, audio);
|
|
|
|
|
|
_allAudioDic.Add(audio.audioID, audio);
|
|
|
|
|
|
return audio;
|
|
|
|
|
|
}
|
2024-07-17 13:59:24 +08:00
|
|
|
|
|
2024-10-12 18:21:33 +08:00
|
|
|
|
private AudioInst _CreateNewAudio(AudioBase.AudioType audioType, bool isLoop)
|
2024-07-17 13:59:24 +08:00
|
|
|
|
{
|
|
|
|
|
|
var rootGo = new GameObject()
|
|
|
|
|
|
{
|
|
|
|
|
|
name = "Audio"
|
|
|
|
|
|
};
|
|
|
|
|
|
rootGo.transform.SetParent(AudioRoot.transform);
|
|
|
|
|
|
var audio = new AudioInst(audioType, rootGo, null);
|
2024-07-22 19:35:34 +08:00
|
|
|
|
|
|
|
|
|
|
if (audioType == AudioBase.AudioType.Music)
|
|
|
|
|
|
{
|
|
|
|
|
|
rootGo.name = "music";
|
|
|
|
|
|
rootGo.name += audio.audioID;
|
2024-10-12 18:21:33 +08:00
|
|
|
|
if (isLoop)
|
|
|
|
|
|
{
|
|
|
|
|
|
rootGo.name += "Loop";
|
|
|
|
|
|
_musicAudioLoopDic.TryAdd(audio.audioID, audio);
|
|
|
|
|
|
_musicAudioLoopObj.Add(rootGo);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
_musicAudioDic.TryAdd(audio.audioID, audio);
|
|
|
|
|
|
_musicAudioObj.Add(rootGo);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-05 19:51:12 +08:00
|
|
|
|
if (IsAnalyzer)
|
|
|
|
|
|
{
|
|
|
|
|
|
rootGo.GetComponent<CriAtomSource>().AttachToAnalyzer(analyzer);
|
|
|
|
|
|
}
|
2024-07-22 19:35:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (audioType == AudioBase.AudioType.Sound)
|
|
|
|
|
|
{
|
|
|
|
|
|
rootGo.name = "Sound";
|
|
|
|
|
|
rootGo.name += audio.audioID;
|
2024-10-12 18:21:33 +08:00
|
|
|
|
if (isLoop)
|
|
|
|
|
|
{
|
|
|
|
|
|
rootGo.name += "Loop";
|
|
|
|
|
|
_soundAudioLoopDic.TryAdd(audio.audioID, audio);
|
|
|
|
|
|
_soundAudioLoopObj.Add(rootGo);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
_soundAudioDic.TryAdd(audio.audioID, audio);
|
|
|
|
|
|
_soundAudioObj.Add(rootGo);
|
|
|
|
|
|
}
|
2024-07-22 19:35:34 +08:00
|
|
|
|
}
|
2024-08-01 14:03:20 +08:00
|
|
|
|
_allAudioDic.Add(audio.audioID, audio);
|
2024-07-17 13:59:24 +08:00
|
|
|
|
|
|
|
|
|
|
return audio;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Play
|
|
|
|
|
|
|
2024-07-22 19:35:34 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 调用接口,传obj
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="key"></param>
|
|
|
|
|
|
/// <param name="type"></param>
|
|
|
|
|
|
/// <param name="posObj"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2024-10-12 18:21:33 +08:00
|
|
|
|
private int _PlayAudio(string key, EPlayType type, GameObject posObj = null, bool isLoop = false,
|
2024-09-10 14:56:42 +08:00
|
|
|
|
bool isFade = false)
|
2024-07-17 13:59:24 +08:00
|
|
|
|
{
|
2024-07-31 16:05:26 +08:00
|
|
|
|
if (string.IsNullOrEmpty(key))
|
|
|
|
|
|
{
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
2024-10-17 14:56:45 +08:00
|
|
|
|
|
|
|
|
|
|
//策略2 超过限制不播
|
|
|
|
|
|
// var audioType = AudioBase.AudioType.Music;
|
|
|
|
|
|
// bool isSpeak = false;
|
|
|
|
|
|
// if (type == EPlayType.Sound)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// audioType = AudioBase.AudioType.Sound;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// if (type == EPlayType.Speak)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// audioType = AudioBase.AudioType.Sound;
|
|
|
|
|
|
// isSpeak = true;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// if (_CheckIsAudioLimited(audioType, isSpeak))
|
|
|
|
|
|
// {
|
|
|
|
|
|
// return -1;
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
2024-07-17 13:59:24 +08:00
|
|
|
|
if (CriAtom)
|
|
|
|
|
|
{
|
2024-11-06 15:24:33 +08:00
|
|
|
|
try
|
2024-07-17 13:59:24 +08:00
|
|
|
|
{
|
2024-11-06 15:24:33 +08:00
|
|
|
|
var cueSheetName = _GetCriPath(key);
|
|
|
|
|
|
if (!string.IsNullOrEmpty(cueSheetName))
|
2024-07-17 13:59:24 +08:00
|
|
|
|
{
|
2024-11-06 15:24:33 +08:00
|
|
|
|
if (CriAtom.GetCueSheetInternal(cueSheetName) == null)
|
2024-09-18 12:07:22 +08:00
|
|
|
|
{
|
2024-11-06 15:24:33 +08:00
|
|
|
|
var acbPath = _GetAcbPath(key);
|
|
|
|
|
|
var awbPath = _GetAwbPath(key);
|
|
|
|
|
|
if (string.IsNullOrEmpty(acbPath) || string.IsNullOrEmpty(awbPath))
|
|
|
|
|
|
{
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var cueSheet = CriAtom.AddCueSheet(cueSheetName, acbPath, awbPath, null);
|
2024-09-18 12:07:22 +08:00
|
|
|
|
}
|
2024-07-17 13:59:24 +08:00
|
|
|
|
}
|
2024-09-11 14:13:56 +08:00
|
|
|
|
|
2024-11-06 15:24:33 +08:00
|
|
|
|
var criCueSheet = CriAtom.GetCueSheetInternal(cueSheetName);
|
|
|
|
|
|
if (criCueSheet != null && criCueSheet.acb != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var cueInfoList = CriAtom.GetCueSheetInternal(cueSheetName).acb.GetCueInfoList();
|
|
|
|
|
|
var cueInfo = Array.Find(cueInfoList, (cue) => cue.name == key);
|
|
|
|
|
|
if (cueInfo.name == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogWarning($"Can not Find Criware Key:{key}");
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2024-09-11 14:13:56 +08:00
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogWarning($"Can not Find Criware Key:{key}");
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
2024-07-17 13:59:24 +08:00
|
|
|
|
}
|
2024-11-06 15:24:33 +08:00
|
|
|
|
catch (Exception e)
|
2024-09-11 14:15:00 +08:00
|
|
|
|
{
|
2024-11-06 15:24:33 +08:00
|
|
|
|
DebugUtil.LogError($"AudioManager, CriAtom Exception.");
|
2024-09-11 14:15:00 +08:00
|
|
|
|
}
|
2024-07-17 13:59:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-22 19:35:34 +08:00
|
|
|
|
string path = _GetCriPath(key);
|
2024-07-17 13:59:24 +08:00
|
|
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
|
|
{
|
|
|
|
|
|
case EPlayType.Music:
|
|
|
|
|
|
{
|
2024-10-12 18:21:33 +08:00
|
|
|
|
return _PlayMusic(key, path, posObj, isLoop, isFade);
|
2024-07-17 13:59:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
case EPlayType.Sound:
|
|
|
|
|
|
{
|
2024-10-12 18:21:33 +08:00
|
|
|
|
return _PlaySound(key, path, posObj, isLoop, isFade);
|
2024-07-17 13:59:24 +08:00
|
|
|
|
}
|
2024-07-22 19:35:34 +08:00
|
|
|
|
case EPlayType.Speak:
|
|
|
|
|
|
{
|
2024-09-10 14:56:42 +08:00
|
|
|
|
return _PlaySpeakSound(key, path, posObj, isFade);
|
2024-07-22 19:35:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
default: break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 调用接口,传位置
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="key"></param>
|
|
|
|
|
|
/// <param name="type"></param>
|
|
|
|
|
|
/// <param name="pos"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2024-10-10 18:55:19 +08:00
|
|
|
|
private int _PlayAudio(string key, EPlayType type, Vector3 pos, bool loop = false,
|
2024-09-10 14:56:42 +08:00
|
|
|
|
bool isFade = false)
|
2024-07-22 19:35:34 +08:00
|
|
|
|
{
|
2024-10-17 14:56:45 +08:00
|
|
|
|
//策略2 超过限制不播
|
|
|
|
|
|
// var audioType = AudioBase.AudioType.Music;
|
|
|
|
|
|
// bool isSpeak = false;
|
|
|
|
|
|
// if (type == EPlayType.Sound)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// audioType = AudioBase.AudioType.Sound;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// if (type == EPlayType.Speak)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// audioType = AudioBase.AudioType.Sound;
|
|
|
|
|
|
// isSpeak = true;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// if (_CheckIsAudioLimited(audioType, isSpeak))
|
|
|
|
|
|
// {
|
|
|
|
|
|
// return -1;
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
2024-07-22 19:35:34 +08:00
|
|
|
|
if (CriAtom)
|
|
|
|
|
|
{
|
2024-08-08 15:07:48 +08:00
|
|
|
|
var cueSheetName = _GetCriPath(key);
|
|
|
|
|
|
if (CriAtom.GetCueSheetInternal(cueSheetName) == null)
|
2024-07-22 19:35:34 +08:00
|
|
|
|
{
|
|
|
|
|
|
var acbPath = _GetAcbPath(key);
|
|
|
|
|
|
var awbPath = _GetAwbPath(key);
|
|
|
|
|
|
if (string.IsNullOrEmpty(acbPath) || string.IsNullOrEmpty(awbPath))
|
|
|
|
|
|
{
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
2024-09-04 16:02:38 +08:00
|
|
|
|
var cueSheet = CriAtom.AddCueSheet(cueSheetName, acbPath, awbPath, null);
|
|
|
|
|
|
}
|
2024-10-28 19:11:12 +08:00
|
|
|
|
|
|
|
|
|
|
CriAtomEx.CueInfo[] cueInfos;
|
|
|
|
|
|
if (!_cacheCueInfoArrays.ContainsKey(cueSheetName))
|
|
|
|
|
|
{
|
|
|
|
|
|
cueInfos = CriAtom.GetCueSheetInternal(cueSheetName).acb.GetCueInfoList();
|
|
|
|
|
|
_cacheCueInfoArrays.Add(cueSheetName, cueInfos);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
cueInfos = _cacheCueInfoArrays[cueSheetName];
|
|
|
|
|
|
}
|
|
|
|
|
|
// var cueInfoList = CriAtom.GetCueSheetInternal(cueSheetName).acb.GetCueInfoList();
|
|
|
|
|
|
var cueInfo = Array.Find(cueInfos, (cue) => cue.name == key );
|
2024-09-04 16:02:38 +08:00
|
|
|
|
if (cueInfo.name == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogWarning($"Can not Find Criware Key:{key}");
|
|
|
|
|
|
return -1;
|
2024-07-22 19:35:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string path = _GetCriPath(key);
|
|
|
|
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
|
|
{
|
|
|
|
|
|
case EPlayType.Music:
|
|
|
|
|
|
{
|
2024-10-12 18:21:33 +08:00
|
|
|
|
return _PlayMusic(key, path, pos, loop);
|
2024-07-22 19:35:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
case EPlayType.Sound:
|
|
|
|
|
|
{
|
2024-10-10 18:55:19 +08:00
|
|
|
|
return _PlaySound(key, path, pos, loop, isFade);
|
2024-07-22 19:35:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
case EPlayType.Speak:
|
|
|
|
|
|
{
|
|
|
|
|
|
return _PlaySpeakSound(key, path, pos);
|
|
|
|
|
|
}
|
2024-07-17 13:59:24 +08:00
|
|
|
|
default: break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-12 18:21:33 +08:00
|
|
|
|
private int _PlayMusic(string key, string path, GameObject posObj = null, bool isLoop = true, bool isFade = false, float volume = 1f)
|
2024-07-17 13:59:24 +08:00
|
|
|
|
{
|
2024-09-10 14:56:42 +08:00
|
|
|
|
if (!isFade)
|
2024-07-22 19:35:34 +08:00
|
|
|
|
{
|
2024-10-12 16:36:10 +08:00
|
|
|
|
// if (_bgmAudio != null)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// _bgmAudio.Stop();
|
|
|
|
|
|
// }
|
2024-09-10 14:56:42 +08:00
|
|
|
|
AudioInfo audioInfo = new AudioInfo()
|
|
|
|
|
|
{
|
|
|
|
|
|
persist = true,
|
|
|
|
|
|
volume = 1,
|
|
|
|
|
|
fadeInValue = 0.3f,
|
|
|
|
|
|
fadeOutValue = 0.3f,
|
|
|
|
|
|
};
|
2024-10-12 18:21:33 +08:00
|
|
|
|
var audio = _GetUsableAudio(AudioBase.AudioType.Music, isLoop);
|
2024-11-06 15:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
//错误打印,保护
|
|
|
|
|
|
if (audio == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogError($"AudioManager, PlayMusic, Cant GetUsableAudio key:{key}");
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-10 14:56:42 +08:00
|
|
|
|
audio.SetPosObj(posObj);
|
|
|
|
|
|
audio.SetIsSpeak(false);
|
|
|
|
|
|
audio.SetVolume(volume);
|
2024-10-16 15:18:33 +08:00
|
|
|
|
audio.SetIsLoop(isLoop);
|
2024-10-12 16:36:10 +08:00
|
|
|
|
// if (_bgmAudio != null && _bgmAudio != audio)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// _bgmAudio.Stop();
|
|
|
|
|
|
// }
|
|
|
|
|
|
audio.Stop();
|
2024-09-10 14:56:42 +08:00
|
|
|
|
audio.Play(path, key);
|
2024-10-16 15:18:33 +08:00
|
|
|
|
audio.SetIsLoop(isLoop);
|
2024-10-12 18:21:33 +08:00
|
|
|
|
//_bgmAudio = audio;
|
2024-09-10 14:56:42 +08:00
|
|
|
|
return audio.audioID;
|
2024-07-22 19:35:34 +08:00
|
|
|
|
}
|
2024-09-10 14:56:42 +08:00
|
|
|
|
else
|
2024-07-17 13:59:24 +08:00
|
|
|
|
{
|
2024-09-10 14:56:42 +08:00
|
|
|
|
AudioInfo audioInfo = new AudioInfo()
|
|
|
|
|
|
{
|
|
|
|
|
|
persist = true,
|
|
|
|
|
|
volume = 1,
|
|
|
|
|
|
fadeInValue = 0.3f,
|
|
|
|
|
|
fadeOutValue = 0.3f,
|
|
|
|
|
|
};
|
2024-10-12 18:21:33 +08:00
|
|
|
|
var audio = _GetUsableAudio(AudioBase.AudioType.Music, isLoop);
|
2024-09-10 14:56:42 +08:00
|
|
|
|
audio.SetPosObj(posObj);
|
|
|
|
|
|
audio.SetIsSpeak(false);
|
2024-10-12 16:36:10 +08:00
|
|
|
|
// if (_bgmAudio != null && _bgmAudio != audio)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// _bgmAudio.Stop();
|
|
|
|
|
|
// }
|
2024-09-10 14:56:42 +08:00
|
|
|
|
|
2024-09-10 16:21:12 +08:00
|
|
|
|
//audio.SetIsFadeIn(true);
|
2024-10-12 16:36:10 +08:00
|
|
|
|
audio.Stop();
|
2024-09-10 14:56:42 +08:00
|
|
|
|
audio.PlayWithFade(path, key);
|
2024-10-12 18:21:33 +08:00
|
|
|
|
audio.SetIsLoop(isLoop);
|
2024-10-12 16:36:10 +08:00
|
|
|
|
//_bgmAudio = audio;
|
2024-09-10 14:56:42 +08:00
|
|
|
|
return audio.audioID;
|
2024-07-22 19:35:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-10-12 16:36:10 +08:00
|
|
|
|
|
2024-10-12 18:21:33 +08:00
|
|
|
|
private int _PlayMusic(string key, string path, Vector3 pos, bool isLoop, bool isFade = false, float volume = 1f)
|
2024-07-22 19:35:34 +08:00
|
|
|
|
{
|
|
|
|
|
|
AudioInfo audioInfo = new AudioInfo()
|
|
|
|
|
|
{
|
|
|
|
|
|
persist = true,
|
|
|
|
|
|
volume = 1,
|
|
|
|
|
|
fadeInValue = 0.3f,
|
|
|
|
|
|
fadeOutValue = 0.3f,
|
|
|
|
|
|
};
|
2024-10-12 18:21:33 +08:00
|
|
|
|
var audio = _GetUsableAudio(AudioBase.AudioType.Music, isLoop);
|
2024-11-06 15:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
//错误打印,保护
|
|
|
|
|
|
if (audio == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogError($"AudioManager, PlayMusic By Pos, Cant GetUsableAudio key:{key}");
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-22 19:35:34 +08:00
|
|
|
|
audio.SetPos(pos);
|
|
|
|
|
|
audio.SetIsSpeak(false);
|
2024-09-10 14:56:42 +08:00
|
|
|
|
|
2024-10-12 16:36:10 +08:00
|
|
|
|
// if (_bgmAudio != null && _bgmAudio != audio)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// _bgmAudio.Stop();
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
2024-10-12 18:21:33 +08:00
|
|
|
|
audio.SetIsLoop(true);
|
2024-10-12 16:36:10 +08:00
|
|
|
|
audio.Stop();
|
2024-09-10 14:56:42 +08:00
|
|
|
|
if (isFade)
|
|
|
|
|
|
{
|
|
|
|
|
|
audio.PlayWithFade(path, key);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
audio.Play(path, key);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-12 18:21:33 +08:00
|
|
|
|
//_bgmAudio = audio;
|
2024-10-12 16:36:10 +08:00
|
|
|
|
|
2024-10-12 18:21:33 +08:00
|
|
|
|
audio.SetIsLoop(isLoop);
|
2024-07-23 19:32:40 +08:00
|
|
|
|
return audio.audioID;
|
2024-07-17 13:59:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-12 18:21:33 +08:00
|
|
|
|
private int _PlaySound(string key, string path, GameObject posObj = null, bool isLoop = false,
|
2024-10-10 18:55:19 +08:00
|
|
|
|
bool isFade = false, float volume = 1f)
|
2024-07-17 13:59:24 +08:00
|
|
|
|
{
|
|
|
|
|
|
AudioInfo audioInfo = new AudioInfo()
|
|
|
|
|
|
{
|
|
|
|
|
|
persist = true,
|
|
|
|
|
|
volume = 1,
|
|
|
|
|
|
fadeInValue = 0.3f,
|
|
|
|
|
|
fadeOutValue = 0.3f,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-10-12 18:21:33 +08:00
|
|
|
|
var audio = _GetUsableAudio(AudioBase.AudioType.Sound, isLoop);
|
2024-11-06 15:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
//错误打印,保护
|
|
|
|
|
|
if (audio == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogError($"AudioManager, PlaySound By Obj, Cant GetUsableAudio key:{key}");
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-16 15:18:33 +08:00
|
|
|
|
audio.Stop();
|
|
|
|
|
|
|
2024-07-17 13:59:24 +08:00
|
|
|
|
audio.SetPosObj(posObj);
|
2024-07-22 19:35:34 +08:00
|
|
|
|
audio.SetIsSpeak(false);
|
2024-10-23 16:15:19 +08:00
|
|
|
|
audio.SetIsLoop(isLoop);
|
2024-09-03 13:17:55 +08:00
|
|
|
|
if (posObj)
|
|
|
|
|
|
{
|
|
|
|
|
|
audio.SetIs3D(true);
|
|
|
|
|
|
}
|
2024-09-10 14:56:42 +08:00
|
|
|
|
|
|
|
|
|
|
if (isFade)
|
|
|
|
|
|
{
|
|
|
|
|
|
audio.SetVolume(0);
|
|
|
|
|
|
audio.PlayWithFade(path, key);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
audio.SetVolume(volume);
|
|
|
|
|
|
audio.Play(path, key);
|
|
|
|
|
|
}
|
2024-07-17 13:59:24 +08:00
|
|
|
|
|
2024-10-12 18:21:33 +08:00
|
|
|
|
audio.SetIsLoop(isLoop);
|
2024-07-23 19:32:40 +08:00
|
|
|
|
return audio.audioID;
|
2024-07-17 13:59:24 +08:00
|
|
|
|
}
|
2024-07-22 19:35:34 +08:00
|
|
|
|
|
2024-10-10 18:55:19 +08:00
|
|
|
|
private int _PlaySound(string key, string path, Vector3 pos, bool isLoop = false, bool isFade = false, float volume = 1f)
|
2024-07-22 19:35:34 +08:00
|
|
|
|
{
|
|
|
|
|
|
AudioInfo audioInfo = new AudioInfo()
|
|
|
|
|
|
{
|
|
|
|
|
|
persist = true,
|
|
|
|
|
|
volume = 1,
|
|
|
|
|
|
fadeInValue = 0.3f,
|
|
|
|
|
|
fadeOutValue = 0.3f,
|
|
|
|
|
|
};
|
2024-10-12 18:21:33 +08:00
|
|
|
|
var audio = _GetUsableAudio(AudioBase.AudioType.Sound, isLoop);
|
2024-11-06 15:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
//错误打印,保护
|
|
|
|
|
|
if (audio == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogError($"AudioManager, PlaySound By Pos, Cant GetUsableAudio key:{key}");
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-16 15:18:33 +08:00
|
|
|
|
audio.Stop();
|
|
|
|
|
|
|
2024-07-22 19:35:34 +08:00
|
|
|
|
audio.SetPos(pos);
|
2024-10-23 16:15:19 +08:00
|
|
|
|
audio.SetIsLoop(isLoop);
|
2024-07-22 19:35:34 +08:00
|
|
|
|
audio.SetIsSpeak(false);
|
2024-09-03 13:17:55 +08:00
|
|
|
|
audio.SetIs3D(true);
|
2024-09-10 14:56:42 +08:00
|
|
|
|
if (isFade)
|
|
|
|
|
|
{
|
|
|
|
|
|
audio.SetVolume(0);
|
|
|
|
|
|
audio.PlayWithFade(path, key);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
audio.SetVolume(volume);
|
|
|
|
|
|
audio.Play(path, key);
|
|
|
|
|
|
}
|
2024-10-12 15:39:02 +08:00
|
|
|
|
|
|
|
|
|
|
audio.SetIsLoop(isLoop);
|
2024-07-23 19:32:40 +08:00
|
|
|
|
return audio.audioID;
|
2024-07-22 19:35:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-10 14:56:42 +08:00
|
|
|
|
private int _PlaySpeakSound(string key, string path, GameObject posObj = null, bool isFade = false, float volume = 1f)
|
2024-07-22 19:35:34 +08:00
|
|
|
|
{
|
|
|
|
|
|
AudioInfo audioInfo = new AudioInfo()
|
|
|
|
|
|
{
|
|
|
|
|
|
persist = true,
|
|
|
|
|
|
volume = 1,
|
|
|
|
|
|
fadeInValue = 0.3f,
|
|
|
|
|
|
fadeOutValue = 0.3f,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-10-12 18:21:33 +08:00
|
|
|
|
var audio = _GetUsableAudio(AudioBase.AudioType.Sound, false);
|
2024-11-06 15:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
//错误打印,保护
|
|
|
|
|
|
if (audio == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogError($"AudioManager, PlaySpeak By Obj, Cant GetUsableAudio key:{key}");
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-22 19:35:34 +08:00
|
|
|
|
audio.SetPosObj(posObj);
|
|
|
|
|
|
audio.SetIsSpeak(true);
|
2024-10-23 16:15:19 +08:00
|
|
|
|
|
2024-09-10 14:56:42 +08:00
|
|
|
|
if (isFade)
|
|
|
|
|
|
{
|
|
|
|
|
|
audio.SetVolume(0);
|
|
|
|
|
|
audio.PlayWithFade(path, key);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
audio.SetVolume(volume);
|
|
|
|
|
|
audio.Play(path, key);
|
|
|
|
|
|
}
|
2024-10-12 16:36:10 +08:00
|
|
|
|
audio.SetIsLoop(false);
|
2024-07-22 19:35:34 +08:00
|
|
|
|
|
2024-10-12 16:36:10 +08:00
|
|
|
|
return audio.audioID;
|
2024-07-22 19:35:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-10 14:56:42 +08:00
|
|
|
|
private int _PlaySpeakSound(string key, string path, Vector3 pos, bool isFade = false, float volume = 1f)
|
2024-07-22 19:35:34 +08:00
|
|
|
|
{
|
|
|
|
|
|
AudioInfo audioInfo = new AudioInfo()
|
|
|
|
|
|
{
|
|
|
|
|
|
persist = true,
|
|
|
|
|
|
volume = 1,
|
|
|
|
|
|
fadeInValue = 0.3f,
|
|
|
|
|
|
fadeOutValue = 0.3f,
|
|
|
|
|
|
};
|
2024-10-12 18:21:33 +08:00
|
|
|
|
var audio = _GetUsableAudio(AudioBase.AudioType.Sound, false);
|
2024-07-22 19:35:34 +08:00
|
|
|
|
audio.SetPos(pos);
|
|
|
|
|
|
audio.SetIsSpeak(true);
|
2024-09-10 14:56:42 +08:00
|
|
|
|
if (isFade)
|
|
|
|
|
|
{
|
|
|
|
|
|
audio.SetVolume(0);
|
|
|
|
|
|
audio.PlayWithFade(path, key);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
audio.SetVolume(volume);
|
|
|
|
|
|
audio.Play(path, key);
|
|
|
|
|
|
}
|
2024-10-12 16:36:10 +08:00
|
|
|
|
audio.SetIsLoop(false);
|
|
|
|
|
|
return audio.audioID;
|
2024-07-22 19:35:34 +08:00
|
|
|
|
}
|
2024-07-31 16:05:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void _PlayAudioByID(int id, string key, EPlayType type, GameObject posObj = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_soundAudioDic.TryGetValue(id, out var audio))
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-07-17 13:59:24 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region API
|
|
|
|
|
|
|
2024-10-10 18:55:19 +08:00
|
|
|
|
public int PlayAudio(string key, EPlayType type, GameObject posObj = null, bool loop = false,
|
2024-09-10 14:56:42 +08:00
|
|
|
|
bool isFade = false)
|
2024-07-17 13:59:24 +08:00
|
|
|
|
{
|
2024-11-20 12:04:06 +08:00
|
|
|
|
// #if DEVELOPMENT_BUILD || DEBUG
|
|
|
|
|
|
// DebugUtil.Log("播放音频:{0}, type:{1}", key, type);
|
|
|
|
|
|
// #endif
|
2024-10-10 18:55:19 +08:00
|
|
|
|
return _PlayAudio(key, type, posObj, loop, isFade);
|
2024-07-17 13:59:24 +08:00
|
|
|
|
}
|
2024-07-22 19:35:34 +08:00
|
|
|
|
|
2024-10-10 18:55:19 +08:00
|
|
|
|
public int PlayAudio(string key, EPlayType type, Vector3 pos, bool loop = false,
|
2024-09-10 14:56:42 +08:00
|
|
|
|
bool isFade = false)
|
2024-07-22 19:35:34 +08:00
|
|
|
|
{
|
2024-11-20 12:04:06 +08:00
|
|
|
|
// #if DEVELOPMENT_BUILD || DEBUG
|
|
|
|
|
|
// DebugUtil.Log("播放音频:{0}, type:{1}", key, type);
|
|
|
|
|
|
// #endif
|
2024-10-10 18:55:19 +08:00
|
|
|
|
return _PlayAudio(key, type, pos, loop, isFade);
|
2024-07-22 19:35:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int PlayAudio()
|
|
|
|
|
|
{
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-16 16:03:13 +08:00
|
|
|
|
public void InitLimit(int count0, int count1, int count2)
|
|
|
|
|
|
{
|
|
|
|
|
|
MusicPoolLimit = count0;
|
|
|
|
|
|
SoundPoolLimit = count1;
|
|
|
|
|
|
SpeakPoolLimit = count2;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-22 19:35:34 +08:00
|
|
|
|
public AudioInst GetAudioByID(EPlayType audioType, int id)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (audioType == EPlayType.Music)
|
|
|
|
|
|
{
|
2024-10-12 18:21:33 +08:00
|
|
|
|
if (_musicAudioDic.ContainsKey(id))
|
2024-07-22 19:35:34 +08:00
|
|
|
|
{
|
2024-10-12 18:21:33 +08:00
|
|
|
|
return _musicAudioDic[id];
|
2024-07-22 19:35:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-12 18:21:33 +08:00
|
|
|
|
if (_musicAudioLoopDic.ContainsKey(id))
|
|
|
|
|
|
{
|
|
|
|
|
|
return _musicAudioLoopDic[id];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
2024-07-22 19:35:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (audioType == EPlayType.Sound || audioType == EPlayType.Speak)
|
|
|
|
|
|
{
|
2024-10-12 18:21:33 +08:00
|
|
|
|
if (_soundAudioDic.ContainsKey(id))
|
2024-07-22 19:35:34 +08:00
|
|
|
|
{
|
2024-10-12 18:21:33 +08:00
|
|
|
|
return _soundAudioDic[id];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (_soundAudioLoopDic.ContainsKey(id))
|
|
|
|
|
|
{
|
|
|
|
|
|
return _soundAudioLoopDic[id];
|
2024-07-22 19:35:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-12 18:21:33 +08:00
|
|
|
|
return null;
|
2024-07-22 19:35:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2024-10-16 15:18:33 +08:00
|
|
|
|
|
|
|
|
|
|
public AudioInst GetAudioByID(int id)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_musicAudioDic.ContainsKey(id))
|
|
|
|
|
|
{
|
|
|
|
|
|
return _musicAudioDic[id];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (_musicAudioLoopDic.ContainsKey(id))
|
|
|
|
|
|
{
|
|
|
|
|
|
return _musicAudioLoopDic[id];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (_soundAudioDic.ContainsKey(id))
|
|
|
|
|
|
{
|
|
|
|
|
|
return _soundAudioDic[id];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (_soundAudioLoopDic.ContainsKey(id))
|
|
|
|
|
|
{
|
|
|
|
|
|
return _soundAudioLoopDic[id];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-22 19:35:34 +08:00
|
|
|
|
public void StopMusicById(int audioID)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (audioID >= 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(_musicAudioDic.TryGetValue(audioID, out var audio))
|
|
|
|
|
|
{
|
|
|
|
|
|
audio.Stop();
|
|
|
|
|
|
}
|
2024-10-12 18:21:33 +08:00
|
|
|
|
|
|
|
|
|
|
if(_musicAudioLoopDic.TryGetValue(audioID, out var audioLoop))
|
|
|
|
|
|
{
|
|
|
|
|
|
audioLoop.Stop();
|
|
|
|
|
|
}
|
2024-07-22 19:35:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-09-10 16:21:12 +08:00
|
|
|
|
|
|
|
|
|
|
public void StopSoundByID(int audioID)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (audioID >= 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(_soundAudioDic.TryGetValue(audioID, out var audio))
|
|
|
|
|
|
{
|
|
|
|
|
|
audio.Stop();
|
|
|
|
|
|
}
|
2024-10-12 18:21:33 +08:00
|
|
|
|
|
|
|
|
|
|
if(_soundAudioLoopDic.TryGetValue(audioID, out var audioLoop))
|
|
|
|
|
|
{
|
|
|
|
|
|
audioLoop.Stop();
|
|
|
|
|
|
}
|
2024-09-10 16:21:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void StopByID(int audioID)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (audioID >= 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(_musicAudioDic.TryGetValue(audioID, out var audio))
|
|
|
|
|
|
{
|
|
|
|
|
|
audio.Stop();
|
|
|
|
|
|
}
|
2024-10-12 18:21:33 +08:00
|
|
|
|
|
|
|
|
|
|
if(_musicAudioLoopDic.TryGetValue(audioID, out var audioLoop))
|
|
|
|
|
|
{
|
|
|
|
|
|
audioLoop.Stop();
|
|
|
|
|
|
}
|
2024-09-10 16:21:12 +08:00
|
|
|
|
|
|
|
|
|
|
if (_soundAudioDic.TryGetValue(audioID, out var soundAudio))
|
|
|
|
|
|
{
|
|
|
|
|
|
soundAudio.Stop();
|
|
|
|
|
|
}
|
2024-10-12 18:21:33 +08:00
|
|
|
|
|
|
|
|
|
|
if(_soundAudioLoopDic.TryGetValue(audioID, out var audioLoop1))
|
|
|
|
|
|
{
|
|
|
|
|
|
audioLoop1.Stop();
|
|
|
|
|
|
}
|
2024-09-10 16:21:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2024-07-22 19:35:34 +08:00
|
|
|
|
|
|
|
|
|
|
public void StopAllMusic()
|
|
|
|
|
|
{
|
2024-10-12 16:38:07 +08:00
|
|
|
|
// if (_bgmAudio != null)
|
2024-07-22 19:35:34 +08:00
|
|
|
|
// {
|
2024-10-12 16:38:07 +08:00
|
|
|
|
// _bgmAudio.Stop();
|
2024-07-22 19:35:34 +08:00
|
|
|
|
// }
|
2024-10-12 16:38:07 +08:00
|
|
|
|
foreach (var kv in _musicAudioDic)
|
|
|
|
|
|
{
|
|
|
|
|
|
var audio = kv.Value;
|
|
|
|
|
|
audio.Stop();
|
|
|
|
|
|
}
|
2024-10-12 18:21:33 +08:00
|
|
|
|
|
|
|
|
|
|
foreach (var kv in _musicAudioLoopDic)
|
|
|
|
|
|
{
|
|
|
|
|
|
var audio = kv.Value;
|
|
|
|
|
|
audio.Stop();
|
|
|
|
|
|
}
|
2024-07-22 19:35:34 +08:00
|
|
|
|
}
|
2024-07-17 13:59:24 +08:00
|
|
|
|
|
2024-07-22 19:35:34 +08:00
|
|
|
|
public void StopAllSounds()
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var kv in _soundAudioDic)
|
|
|
|
|
|
{
|
|
|
|
|
|
var audio = kv.Value;
|
|
|
|
|
|
audio.Stop();
|
|
|
|
|
|
}
|
2024-10-12 18:21:33 +08:00
|
|
|
|
|
|
|
|
|
|
foreach (var kv in _soundAudioLoopDic)
|
|
|
|
|
|
{
|
|
|
|
|
|
var audio = kv.Value;
|
|
|
|
|
|
audio.Stop();
|
|
|
|
|
|
}
|
2024-07-22 19:35:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-08 16:59:48 +08:00
|
|
|
|
public void StopAllSpeaks()
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var kv in _soundAudioDic)
|
|
|
|
|
|
{
|
|
|
|
|
|
var audio = kv.Value;
|
|
|
|
|
|
if(audio.IsSpeak)
|
|
|
|
|
|
audio.Stop();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-22 19:35:34 +08:00
|
|
|
|
public void StopAll()
|
|
|
|
|
|
{
|
2024-08-23 19:53:32 +08:00
|
|
|
|
foreach (var kv in _allAudioDic)
|
2024-07-22 19:35:34 +08:00
|
|
|
|
{
|
|
|
|
|
|
var audio = kv.Value;
|
|
|
|
|
|
audio.Stop();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void ResumeAllMusic()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
2024-10-12 16:38:07 +08:00
|
|
|
|
// if (_bgmAudio != null)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// _bgmAudio.Resume();
|
|
|
|
|
|
// }
|
|
|
|
|
|
foreach (var kv in _musicAudioDic)
|
2024-07-22 19:35:34 +08:00
|
|
|
|
{
|
2024-10-12 16:38:07 +08:00
|
|
|
|
var audio = kv.Value;
|
|
|
|
|
|
audio.Resume();
|
2024-07-22 19:35:34 +08:00
|
|
|
|
}
|
2024-10-12 18:21:33 +08:00
|
|
|
|
|
|
|
|
|
|
foreach (var kv in _musicAudioLoopDic)
|
|
|
|
|
|
{
|
|
|
|
|
|
var audio = kv.Value;
|
|
|
|
|
|
audio.Resume();
|
|
|
|
|
|
}
|
2024-07-22 19:35:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void StopBGM()
|
|
|
|
|
|
{
|
|
|
|
|
|
_bgmAudio.Stop();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void AfterSwitchMainCamera(Camera camera)
|
|
|
|
|
|
{
|
|
|
|
|
|
var listener = camera.GetComponent<CriAtomListener>();
|
|
|
|
|
|
if (!listener)
|
|
|
|
|
|
{
|
|
|
|
|
|
camera.gameObject.AddComponent<CriAtomListener>();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public CriAtomExAcb GetAcb(string cueSheetName)
|
|
|
|
|
|
{
|
|
|
|
|
|
return CriAtom.GetAcb(cueSheetName);
|
|
|
|
|
|
}
|
2024-08-01 14:03:20 +08:00
|
|
|
|
|
|
|
|
|
|
public AudioInst GetStoryAudioInst()
|
|
|
|
|
|
{
|
|
|
|
|
|
return _CreateStoryAudio();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void ReleaseStoryAudios()
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var kv in _storyAudioDic)
|
|
|
|
|
|
{
|
|
|
|
|
|
var audio = kv.Value;
|
2024-10-16 15:18:33 +08:00
|
|
|
|
audio.Stop();
|
2024-08-01 14:03:20 +08:00
|
|
|
|
Object.Destroy(audio.RootGo);
|
|
|
|
|
|
_allAudioDic.Remove(audio.audioID);
|
|
|
|
|
|
}
|
|
|
|
|
|
_storyAudioDic.Clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-11 19:59:36 +08:00
|
|
|
|
public void PlayByCueName(int audioID, string cueName, bool isFade = false)
|
2024-08-01 14:03:20 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (_allAudioDic.TryGetValue(audioID, out var audio))
|
|
|
|
|
|
{
|
|
|
|
|
|
var cueSheet = _GetCriPath(cueName);
|
2024-09-11 19:59:36 +08:00
|
|
|
|
if (isFade)
|
|
|
|
|
|
{
|
|
|
|
|
|
audio.PlayWithFade(cueSheet, cueName);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
audio.Play(cueSheet, cueName);
|
|
|
|
|
|
}
|
2024-08-01 14:03:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-08-23 19:53:32 +08:00
|
|
|
|
|
|
|
|
|
|
public void ReleaseMusicAudios()
|
|
|
|
|
|
{
|
|
|
|
|
|
var musicAudioList = _musicAudioDic.ToList();
|
|
|
|
|
|
for (int i = musicAudioList.Count - 1; i >= 0; i--)
|
|
|
|
|
|
{
|
|
|
|
|
|
var kv = musicAudioList[i];
|
|
|
|
|
|
var audio = kv.Value;
|
|
|
|
|
|
var audioID = kv.Key;
|
|
|
|
|
|
audio.Stop();
|
|
|
|
|
|
_musicAudioDic.Remove(audioID);
|
|
|
|
|
|
_allAudioDic.Remove(audioID);
|
|
|
|
|
|
Object.Destroy(audio.RootGo);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-12 18:21:33 +08:00
|
|
|
|
var musicAudioLoopList = _musicAudioLoopDic.ToList();
|
|
|
|
|
|
for (int i = musicAudioLoopList.Count - 1; i >= 0; i--)
|
|
|
|
|
|
{
|
|
|
|
|
|
var kv = musicAudioLoopList[i];
|
|
|
|
|
|
var audio = kv.Value;
|
|
|
|
|
|
var audioID = kv.Key;
|
|
|
|
|
|
audio.Stop();
|
|
|
|
|
|
_musicAudioLoopDic.Remove(audioID);
|
|
|
|
|
|
_allAudioDic.Remove(audioID);
|
|
|
|
|
|
Object.Destroy(audio.RootGo);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-23 19:53:32 +08:00
|
|
|
|
_musicAudioObj.Clear();
|
|
|
|
|
|
_musicAudioDic.Clear();
|
2024-10-12 18:21:33 +08:00
|
|
|
|
_musicAudioLoopObj.Clear();
|
|
|
|
|
|
_musicAudioLoopDic.Clear();
|
2024-08-23 19:53:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void ReleaseSoundsAudios()
|
|
|
|
|
|
{
|
|
|
|
|
|
var soundAudioList = _soundAudioDic.ToList();
|
|
|
|
|
|
for (int i = soundAudioList.Count - 1; i >= 0; i--)
|
|
|
|
|
|
{
|
|
|
|
|
|
var kv = soundAudioList[i];
|
|
|
|
|
|
var audio = kv.Value;
|
|
|
|
|
|
var audioID = kv.Key;
|
|
|
|
|
|
audio.Stop();
|
|
|
|
|
|
_soundAudioDic.Remove(audioID);
|
|
|
|
|
|
_allAudioDic.Remove(audioID);
|
|
|
|
|
|
Object.Destroy(audio.RootGo);
|
|
|
|
|
|
}
|
2024-10-12 18:21:33 +08:00
|
|
|
|
|
|
|
|
|
|
var soundAudioLoopList = _soundAudioLoopDic.ToList();
|
|
|
|
|
|
for (int i = soundAudioLoopList.Count - 1; i >= 0; i--)
|
|
|
|
|
|
{
|
|
|
|
|
|
var kv = soundAudioLoopList[i];
|
|
|
|
|
|
var audio = kv.Value;
|
|
|
|
|
|
var audioID = kv.Key;
|
|
|
|
|
|
audio.Stop();
|
|
|
|
|
|
_soundAudioLoopDic.Remove(audioID);
|
|
|
|
|
|
_allAudioDic.Remove(audioID);
|
|
|
|
|
|
Object.Destroy(audio.RootGo);
|
|
|
|
|
|
}
|
2024-08-23 19:53:32 +08:00
|
|
|
|
|
|
|
|
|
|
_soundAudioObj.Clear();
|
|
|
|
|
|
_soundAudioDic.Clear();
|
2024-10-12 18:21:33 +08:00
|
|
|
|
_soundAudioLoopObj.Clear();
|
|
|
|
|
|
_soundAudioLoopDic.Clear();
|
2024-08-23 19:53:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void ReleaseAllAudios()
|
|
|
|
|
|
{
|
|
|
|
|
|
ReleaseMusicAudios();
|
|
|
|
|
|
ReleaseSoundsAudios();
|
|
|
|
|
|
}
|
2024-09-10 16:21:12 +08:00
|
|
|
|
|
|
|
|
|
|
public long GetCueLength(string cueSheet, string cueName)
|
|
|
|
|
|
{
|
|
|
|
|
|
var acb = CriAtom.GetCueSheetInternal(cueSheet).acb;
|
|
|
|
|
|
if (acb.GetCueInfo(cueName, out var cueInfo))
|
|
|
|
|
|
{
|
|
|
|
|
|
var length = cueInfo.length / 1000;
|
|
|
|
|
|
return length;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
2024-10-16 15:18:33 +08:00
|
|
|
|
|
|
|
|
|
|
public void Add2Playing(AudioBase.AudioType audioType, int id, bool isSpeak = false)
|
|
|
|
|
|
{
|
|
|
|
|
|
PlayType type;
|
|
|
|
|
|
if (audioType == AudioBase.AudioType.Music)
|
|
|
|
|
|
{
|
|
|
|
|
|
type = PlayType.Music;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (isSpeak)
|
|
|
|
|
|
type = PlayType.Speak;
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
type = PlayType.Sound;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
var list = _playingLDic[type];
|
|
|
|
|
|
if (!list.Contains(id))
|
|
|
|
|
|
{
|
|
|
|
|
|
list.Add(id);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void RemovePlaying(AudioBase.AudioType audioType, int id, bool isSpeak = false)
|
|
|
|
|
|
{
|
|
|
|
|
|
PlayType type;
|
|
|
|
|
|
if (audioType == AudioBase.AudioType.Music)
|
|
|
|
|
|
{
|
|
|
|
|
|
type = PlayType.Music;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (isSpeak)
|
|
|
|
|
|
type = PlayType.Speak;
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
type = PlayType.Sound;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
var list = _playingLDic[type];
|
|
|
|
|
|
if (list.Contains(id))
|
|
|
|
|
|
{
|
|
|
|
|
|
list.Remove(id);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void RemovePlaying(int id)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var kv in _playingLDic)
|
|
|
|
|
|
{
|
|
|
|
|
|
var list = kv.Value;
|
|
|
|
|
|
if (list.Contains(id))
|
|
|
|
|
|
{
|
|
|
|
|
|
list.Remove(id);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-07-17 13:59:24 +08:00
|
|
|
|
#endregion
|
2024-07-22 19:35:34 +08:00
|
|
|
|
|
2024-07-17 13:59:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class AudioInst : AudioCri
|
|
|
|
|
|
{
|
|
|
|
|
|
public AudioInst(AudioType audioType, GameObject rootGo, GameObject posGo, AudioInfo audioInfo = new(),
|
|
|
|
|
|
bool loop = false, bool is3D = false):base(audioType, rootGo, posGo, audioInfo, loop, is3D)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|