/// <summary> /// 增加声音代理辅助器。 /// </summary> /// <param name="soundGroupName">声音组名称。</param> /// <param name="soundAgentHelper">要增加的声音代理辅助器。</param> public void AddSoundAgentHelper(string soundGroupName, ISoundAgentHelper soundAgentHelper) { if (m_SoundHelper == null) { throw new Exception("You must set sound helper first."); } SoundGroup soundGroup = (SoundGroup)GetSoundGroup(soundGroupName); if (soundGroup == null) { throw new Exception(Utility.Text.Format("Sound group '{0}' is not exist.", soundGroupName)); } soundGroup.AddSoundAgentHelper(m_SoundHelper, soundAgentHelper); }
/// <summary> /// 获取指定声音组。 /// </summary> /// <param name="soundGroupName">声音组名称。</param> /// <returns>要获取的声音组。</returns> public ISoundGroup GetSoundGroup(string soundGroupName) { if (string.IsNullOrEmpty(soundGroupName)) { throw new Exception("Sound group name is invalid."); } SoundGroup soundGroup = null; if (m_SoundGroups.TryGetValue(soundGroupName, out soundGroup)) { return(soundGroup); } return(null); }
/// <summary> /// 播放声音。 /// </summary> /// <param name="soundAssetName">声音资源名称。</param> /// <param name="soundGroupName">声音组名称。</param> /// <param name="priority">加载声音资源的优先级。</param> /// <param name="playSoundParams">播放声音参数。</param> /// <param name="userData">用户自定义数据。</param> /// <returns>声音的序列编号。</returns> public async CFTask <int> PlaySound(string soundAssetName, string soundGroupName, int priority, PlaySoundParams playSoundParams, object userData) { if (m_ResourceManager == null) { throw new Exception("You must set resource manager first."); } if (m_SoundHelper == null) { throw new Exception("You must set sound helper first."); } if (playSoundParams == null) { playSoundParams = PlaySoundParams.Create(); } int serialId = ++m_Serial; PlaySoundErrorCode?errorCode = null; string errorMessage = null; SoundGroup soundGroup = (SoundGroup)GetSoundGroup(soundGroupName); if (soundGroup == null) { errorCode = PlaySoundErrorCode.SoundGroupNotExist; errorMessage = Utility.Text.Format("Sound group '{0}' is not exist.", soundGroupName); } else if (soundGroup.SoundAgentCount <= 0) { errorCode = PlaySoundErrorCode.SoundGroupHasNoAgent; errorMessage = Utility.Text.Format("Sound group '{0}' is have no sound agent.", soundGroupName); } if (errorCode.HasValue) { if (playSoundParams.Referenced) { ReferencePool.Release(playSoundParams); } Log.Info(errorMessage); return(serialId); throw new Exception(errorMessage); } m_SoundsBeingLoaded.Add(serialId); LoadAssetCallbacks loadAsset = await m_ResourceManager.LoadAsset(soundAssetName, AssetCategory.Audio, m_LoadAssetCallbacks, priority, PlaySoundInfo.Create(serialId, soundGroup, playSoundParams, userData)); if (loadAsset.LoadAssetStatus == LoadAssetStatus.Success) { //loadAsset.InvokeCallbackSuccess(); return(serialId); } else { //loadAsset.InvokeCallbackFailed(); return(0); } }