/// <summary> /// 播放一个UI音频剪辑 /// </summary> /// <param name="audioPath">相对路径</param> public void PlayUISound(string audioPath) { if (!CanPlaySoundEffect(SoundType.UI)) { return; } object[] rets = Util.CallMethod("Game", "GetSoundEffectVol", audioPath); float volume = 1f; if (rets != null && rets.Length == 1) { volume = Convert.ToSingle(rets[0]); } string path = string.Concat(GetAudioClipPath(audioPath, (int)SoundType.UI), ".ogg"); this.loadAudioClipPath(path, (int)SoundType.UI, volume * User_Config.volumn) .Then((audioData) => { string audioName = Path.GetFileNameWithoutExtension(path); AudioCompatible audioComp = null; if (audioCompDic.TryGetValue(audioName, out audioComp)) { int uiSoundType = (int)SoundType.UI; foreach (string mutexAudio in audioComp.Mutexs) { if (!IsPlaying(mutexAudio, uiSoundType)) { continue; } //互斥对象正在播放时,检查权重 AudioCompatible mutexComp = null; if (!audioCompDic.TryGetValue(mutexAudio, out mutexComp)) { return; } if (mutexComp.Weight < audioComp.Weight) { StopSound(mutexComp.AudioName, uiSoundType); } } } if (!audioData.audio.isPlaying) { audioData.audio.Play(); } }); }
/// <summary> /// 添加音频的互斥信息 /// </summary> /// <param name="audioName">音频名称</param> /// <param name="weight">权重</param> /// <param name="mutexs">互斥集合</param> public void AddAudioCompatible(string audioName, int weight, string[] mutexs) { if (audioCompDic.ContainsKey(audioName)) { return; } AudioCompatible audioComp = new AudioCompatible(); audioComp.AudioName = audioName; audioComp.Weight = weight; audioComp.Mutexs = new HashSet <string>(mutexs); audioCompDic[audioName] = audioComp; }