/// <summary> /// 初始化声音代理的新实例。 /// </summary> /// <param name="soundGroup">所在的声音组。</param> /// <param name="soundHelper">声音辅助器接口。</param> /// <param name="soundAgentHelper">声音代理辅助器接口。</param> public SoundAgent(SoundGroup soundGroup, ISoundHelper soundHelper, ISoundAgentHelper soundAgentHelper) { if (soundGroup == null) { throw new GameFrameworkException("Sound group is invalid."); } if (soundHelper == null) { throw new GameFrameworkException("Sound helper is invalid."); } if (soundAgentHelper == null) { throw new GameFrameworkException("Sound agent helper is invalid."); } m_SoundGroup = soundGroup; m_SoundHelper = soundHelper; m_SoundAgentHelper = soundAgentHelper; m_SoundAgentHelper.ResetSoundAgent += OnResetSoundAgent; m_SerialId = 0; m_SoundAsset = null; Reset(); }
private void LoadAssetSuccessCallback(string soundAssetName, object soundAsset, float duration, object userData) { PlaySoundInfo playSoundInfo = (PlaySoundInfo)userData; if (playSoundInfo == null) { throw new Exception("Play sound info is invalid."); } if (m_SoundsToReleaseOnLoad.Contains(playSoundInfo.SerialId)) { m_SoundsToReleaseOnLoad.Remove(playSoundInfo.SerialId); if (playSoundInfo.PlaySoundParams.Referenced) { ReferencePool.Release(playSoundInfo.PlaySoundParams); } ReferencePool.Release(playSoundInfo); m_SoundHelper.ReleaseSoundAsset(soundAsset); return; } m_SoundsBeingLoaded.Remove(playSoundInfo.SerialId); PlaySoundErrorCode?errorCode = null; ISoundAgent soundAgent = playSoundInfo.SoundGroup.PlaySound(playSoundInfo.SerialId, soundAsset, playSoundInfo.PlaySoundParams, out errorCode); if (soundAgent != null) { ISoundAgentHelper soundAgentHelper = soundAgent.Helper; soundAgentHelper.OnPlaySoundSuccess(playSoundInfo.UserData, soundAgent); if (playSoundInfo.PlaySoundParams.Referenced) { ReferencePool.Release(playSoundInfo.PlaySoundParams); } ReferencePool.Release(playSoundInfo); return; } m_SoundsToReleaseOnLoad.Remove(playSoundInfo.SerialId); m_SoundHelper.ReleaseSoundAsset(soundAsset); string errorMessage = Utility.Text.Format("Sound group '{0}' play sound '{1}' failure.", playSoundInfo.SoundGroup.Name, soundAssetName); if (playSoundInfo.PlaySoundParams.Referenced) { ReferencePool.Release(playSoundInfo.PlaySoundParams); } ReferencePool.Release(playSoundInfo); throw new Exception(errorMessage); }
/// <summary> /// 增加声音代理辅助器。 /// </summary> /// <param name="soundGroupName">声音组名称。</param> /// <param name="soundAgentHelper">要增加的声音代理辅助器。</param> public void AddSoundAgentHelper(string soundGroupName, ISoundAgentHelper soundAgentHelper) { if (m_SoundHelper == null) { throw new GameFrameworkException("You must set sound helper first."); } SoundGroup soundGroup = (SoundGroup)GetSoundGroup(soundGroupName); if (soundGroup == null) { throw new GameFrameworkException(Utility.Text.Format("Sound group '{0}' is not exist.", soundGroupName)); } soundGroup.AddSoundAgentHelper(m_SoundHelper, soundAgentHelper); }
/// <summary> /// 增加声音代理辅助器。 /// </summary> /// <param name="soundHelper">声音辅助器接口。</param> /// <param name="soundAgentHelper">要增加的声音代理辅助器。</param> public void AddSoundAgentHelper(ISoundHelper soundHelper, ISoundAgentHelper soundAgentHelper) { m_SoundAgents.Add(new SoundAgent(this, soundHelper, soundAgentHelper)); }