/// <summary> /// 播放声音。 /// </summary> /// <param name="soundAssetName">声音资源名称。</param> /// <param name="playSoundParams">播放声音参数。</param> /// <returns>声音的序列编号。</returns> public int PlaySound(string soundAssetName, PlaySoundParams playSoundParams, bool isShort) { if (m_ResManager == null) { throw new LufyException("ResManager is invalid."); } if (playSoundParams != null) { if (isShort) { m_SoundSoundParams = playSoundParams; } else { m_MusicSoundParams = playSoundParams; } } AudioClip clip = null; m_AudioClips.TryGetValue(soundAssetName, out clip); if (clip == null) { m_ResManager.LoadAsset(soundAssetName, m_LoadAssetCallbacks, PlaySoundInfo.Create(playSoundParams, isShort)); } else { internalPlaySound(soundAssetName, clip, playSoundParams, isShort); } return(0); }
/// <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 int PlaySound(string soundAssetName, string soundGroupName, int priority, PlaySoundParams playSoundParams, object userData) { if (m_ResourceManager == null) { throw new GameFrameworkException("You must set resource manager first."); } if (m_SoundHelper == null) { throw new GameFrameworkException("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 (m_PlaySoundFailureEventHandler != null) { m_PlaySoundFailureEventHandler(this, new PlaySoundFailureEventArgs(serialId, soundAssetName, soundGroupName, playSoundParams, errorCode.Value, errorMessage, userData)); if (playSoundParams.Referenced) { ReferencePool.Release(playSoundParams); } return(serialId); } throw new GameFrameworkException(errorMessage); } m_SoundsBeingLoaded.Add(serialId); m_ResourceManager.LoadAsset(soundAssetName, priority, m_LoadAssetCallbacks, PlaySoundInfo.Create(serialId, soundGroup, playSoundParams, userData)); return(serialId); }