/// <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 GXException("You must set resource manager first."); } if (m_SoundHelper == null) { throw new GXException("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) { PlaySoundFailureEventArgs playSoundFailureEventArgs = PlaySoundFailureEventArgs.Create(serialId, soundAssetName, soundGroupName, playSoundParams, errorCode.Value, errorMessage, userData); m_PlaySoundFailureEventHandler(this, playSoundFailureEventArgs); ReferencePool.Release(playSoundFailureEventArgs); if (playSoundParams.Referenced) { ReferencePool.Release(playSoundParams); } return(serialId); } throw new GXException(errorMessage); } m_SoundsBeingLoaded.Add(serialId); m_ResourceManager.LoadAsset(soundAssetName, priority, m_LoadAssetCallbacks, PlaySoundInfo.Create(serialId, soundGroup, playSoundParams, userData)); return(serialId); }
/// <summary> /// 播放声音。 /// </summary> /// <param name="serialId">声音的序列编号。</param> /// <param name="soundAsset">声音资源。</param> /// <param name="playSoundParams">播放声音参数。</param> /// <param name="errorCode">错误码。</param> /// <returns>用于播放的声音代理。</returns> public ISoundAgent PlaySound(int serialId, object soundAsset, PlaySoundParams playSoundParams, out PlaySoundErrorCode?errorCode) { errorCode = null; SoundAgent candidateAgent = null; foreach (SoundAgent soundAgent in m_SoundAgents) { if (!soundAgent.IsPlaying) { candidateAgent = soundAgent; break; } if (soundAgent.Priority < playSoundParams.Priority) { if (candidateAgent == null || soundAgent.Priority < candidateAgent.Priority) { candidateAgent = soundAgent; } } else if (!m_AvoidBeingReplacedBySamePriority && soundAgent.Priority == playSoundParams.Priority) { if (candidateAgent == null || soundAgent.SetSoundAssetTime < candidateAgent.SetSoundAssetTime) { candidateAgent = soundAgent; } } } if (candidateAgent == null) { errorCode = PlaySoundErrorCode.IgnoredDueToLowPriority; return(null); } if (!candidateAgent.SetSoundAsset(soundAsset)) { errorCode = PlaySoundErrorCode.SetSoundAssetFailure; return(null); } candidateAgent.SerialId = serialId; candidateAgent.Time = playSoundParams.Time; candidateAgent.MuteInSoundGroup = playSoundParams.MuteInSoundGroup; candidateAgent.Loop = playSoundParams.Loop; candidateAgent.Priority = playSoundParams.Priority; candidateAgent.VolumeInSoundGroup = playSoundParams.VolumeInSoundGroup; candidateAgent.Pitch = playSoundParams.Pitch; candidateAgent.PanStereo = playSoundParams.PanStereo; candidateAgent.SpatialBlend = playSoundParams.SpatialBlend; candidateAgent.MaxDistance = playSoundParams.MaxDistance; candidateAgent.DopplerLevel = playSoundParams.DopplerLevel; candidateAgent.Play(playSoundParams.FadeInSeconds); return(candidateAgent); }
/// <summary> /// 播放声音。 /// </summary> /// <param name="soundAssetName">声音资源名称。</param> /// <param name="soundGroupName">声音组名称。</param> /// <param name="priority">加载声音资源的优先级。</param> /// <param name="playSoundParams">播放声音参数。</param> /// <returns>声音的序列编号。</returns> public int PlaySound(string soundAssetName, string soundGroupName, int priority, PlaySoundParams playSoundParams) { return(PlaySound(soundAssetName, soundGroupName, priority, playSoundParams, null)); }
/// <summary> /// 播放声音。 /// </summary> /// <param name="soundAssetName">声音资源名称。</param> /// <param name="soundGroupName">声音组名称。</param> /// <param name="playSoundParams">播放声音参数。</param> /// <param name="userData">用户自定义数据。</param> /// <returns>声音的序列编号。</returns> public int PlaySound(string soundAssetName, string soundGroupName, PlaySoundParams playSoundParams, object userData) { return(PlaySound(soundAssetName, soundGroupName, Resource.Constant.DefaultPriority, playSoundParams, userData)); }
/// <summary> /// 播放声音。 /// </summary> /// <param name="soundAssetName">声音资源名称。</param> /// <param name="soundGroupName">声音组名称。</param> /// <param name="playSoundParams">播放声音参数。</param> /// <returns>声音的序列编号。</returns> public int PlaySound(string soundAssetName, string soundGroupName, PlaySoundParams playSoundParams) { return(PlaySound(soundAssetName, soundGroupName, Resource.Constant.DefaultPriority, playSoundParams, null)); }