private void LoadSoundSuccessCallback(string soundAssetName, object soundAsset, float duration, object userData) { PlaySoundInfo playSoundInfo = userData as PlaySoundInfo; if (playSoundInfo == null) { throw new GameFrameworkException("Play sound info is invalid."); } PlaySoundErrorCode?errorCode = null; ISoundAgent soundAgent = playSoundInfo.SoundGroup.PlaySound(playSoundInfo.SerialId, soundAsset, playSoundInfo.PlaySoundParams, out errorCode); if (soundAgent != null) { m_PlaySoundSuccessEventHandler?.Invoke(this, new PlaySoundSuccessEventArgs(playSoundInfo.SerialId, soundAssetName, soundAgent, duration, playSoundInfo.UserData)); } else { m_SoundHelper.ReleaseSoundAsset(soundAsset); string errorMessage = string.Format("Sound group '{0}' play sound '{1}' failure.", playSoundInfo.SoundGroup.Name, soundAssetName); if (m_PlaySoundFailureEventHandler != null) { m_PlaySoundFailureEventHandler(this, new PlaySoundFailureEventArgs(playSoundInfo.SerialId, soundAssetName, playSoundInfo.SoundGroup.Name, playSoundInfo.PlaySoundParams, errorCode.Value, errorMessage, playSoundInfo.UserData)); return; } throw new GameFrameworkException(errorMessage); } }
private void LoadSoundFailureCallback(string soundAssetName, LoadResourceStatus status, string errorMessage, object userData) { PlaySoundInfo playSoundInfo = (PlaySoundInfo)userData; if (playSoundInfo == null) { throw new GameFrameworkException("Play sound info is invalid."); } if (m_SoundsToReleaseOnLoad.Contains(playSoundInfo.SerialId)) { m_SoundsToReleaseOnLoad.Remove(playSoundInfo.SerialId); ReferencePool.Release(playSoundInfo); return; } m_SoundsBeingLoaded.Remove(playSoundInfo.SerialId); string appendErrorMessage = Utility.Text.Format("Load sound failure, asset name '{0}', status '{1}', error message '{2}'.", soundAssetName, status.ToString(), errorMessage); if (m_PlaySoundFailureEventHandler != null) { m_PlaySoundFailureEventHandler(this, new PlaySoundFailureEventArgs(playSoundInfo.SerialId, soundAssetName, playSoundInfo.SoundGroup.Name, playSoundInfo.PlaySoundParams, PlaySoundErrorCode.LoadAssetFailure, appendErrorMessage, playSoundInfo.UserData)); ReferencePool.Release(playSoundInfo); return; } ReferencePool.Release(playSoundInfo); throw new GameFrameworkException(appendErrorMessage); }
/// <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); }
public static PlaySoundInfo Create(PlaySoundParams playSoundParams, bool isShort) { PlaySoundInfo playSoundInfo = ReferencePool.Acquire <PlaySoundInfo>(); playSoundInfo.PlaySoundParams = playSoundParams; playSoundInfo.IsShort = isShort; return(playSoundInfo); }
void LoadAssetSuccess(string assetName, object asset, float duration, object userData) { PlaySoundInfo playSoundInfo = userData as PlaySoundInfo; AudioClip clip = asset as AudioClip; m_AudioClips.Add(assetName, clip); internalPlaySound(assetName, clip, playSoundInfo.PlaySoundParams, playSoundInfo.IsShort); ReferencePool.Release(playSoundInfo); }
public static PlaySoundInfo Create(int serialId, SoundGroup soundGroup, PlaySoundParams playSoundParams, object userData) { PlaySoundInfo playSoundInfo = ReferencePool.Acquire <PlaySoundInfo>(); playSoundInfo.m_SerialId = serialId; playSoundInfo.m_SoundGroup = soundGroup; playSoundInfo.m_PlaySoundParams = playSoundParams; playSoundInfo.m_UserData = userData; return(playSoundInfo); }
private void LoadSoundDependencyAssetCallback(string soundAssetName, string dependencyAssetName, int loadedCount, int totalCount, object userData) { PlaySoundInfo playSoundInfo = userData as PlaySoundInfo; if (playSoundInfo == null) { throw new GameFrameworkException("Play sound info is invalid."); } m_PlaySoundDependencyAssetEventHandler?.Invoke(this, new PlaySoundDependencyAssetEventArgs(playSoundInfo.SerialId, soundAssetName, playSoundInfo.SoundGroup.Name, playSoundInfo.PlaySoundParams, dependencyAssetName, loadedCount, totalCount, playSoundInfo.UserData)); }
private void LoadSoundUpdateCallback(string soundAssetName, float progress, object userData) { PlaySoundInfo playSoundInfo = userData as PlaySoundInfo; if (playSoundInfo == null) { throw new GameFrameworkException("Play sound info is invalid."); } m_PlaySoundUpdateEventHandler?.Invoke(this, new PlaySoundUpdateEventArgs(playSoundInfo.SerialId, soundAssetName, playSoundInfo.SoundGroup.Name, playSoundInfo.PlaySoundParams, progress, playSoundInfo.UserData)); }
private void LoadSoundUpdateCallback(string soundAssetName, float progress, object userData) { PlaySoundInfo playSoundInfo = (PlaySoundInfo)userData; if (playSoundInfo == null) { throw new AshException("Play sound info is invalid."); } if (m_PlaySoundUpdateEventHandler != null) { m_PlaySoundUpdateEventHandler(this, new PlaySoundUpdateEventArgs(playSoundInfo.SerialId, soundAssetName, playSoundInfo.SoundGroup.Name, playSoundInfo.PlaySoundParams, progress, playSoundInfo.UserData)); } }
private void LoadSoundDependencyAssetCallback(string soundAssetName, string dependencyAssetName, int loadedCount, int totalCount, object userData) { PlaySoundInfo playSoundInfo = (PlaySoundInfo)userData; if (playSoundInfo == null) { throw new System.Exception("Play sound info is invalid."); } if (m_PlaySoundDependencyAssetEventHandler != null) { m_PlaySoundDependencyAssetEventHandler(this, new PlaySoundDependencyAssetEventArgs(playSoundInfo.SerialId, soundAssetName, playSoundInfo.SoundGroup.Name, playSoundInfo.PlaySoundParams, dependencyAssetName, loadedCount, totalCount, playSoundInfo.UserData)); } }
private void LoadAssetUpdateCallback(string soundAssetName, float progress, object userData) { PlaySoundInfo playSoundInfo = (PlaySoundInfo)userData; if (playSoundInfo == null) { throw new GameFrameworkException("Play sound info is invalid."); } if (m_PlaySoundUpdateEventHandler != null) { PlaySoundUpdateEventArgs playSoundUpdateEventArgs = PlaySoundUpdateEventArgs.Create(playSoundInfo.SerialId, soundAssetName, playSoundInfo.SoundGroup.Name, playSoundInfo.PlaySoundParams, progress, playSoundInfo.UserData); m_PlaySoundUpdateEventHandler(this, playSoundUpdateEventArgs); ReferencePool.Release(playSoundUpdateEventArgs); } }
private void LoadAssetDependencyAssetCallback(string soundAssetName, string dependencyAssetName, int loadedCount, int totalCount, object userData) { PlaySoundInfo playSoundInfo = (PlaySoundInfo)userData; if (playSoundInfo == null) { throw new GameFrameworkException("Play sound info is invalid."); } if (m_PlaySoundDependencyAssetEventHandler != null) { PlaySoundDependencyAssetEventArgs playSoundDependencyAssetEventArgs = PlaySoundDependencyAssetEventArgs.Create(playSoundInfo.SerialId, soundAssetName, playSoundInfo.SoundGroup.Name, playSoundInfo.PlaySoundParams, dependencyAssetName, loadedCount, totalCount, playSoundInfo.UserData); m_PlaySoundDependencyAssetEventHandler(this, playSoundDependencyAssetEventArgs); ReferencePool.Release(playSoundDependencyAssetEventArgs); } }
private void LoadSoundSuccessCallback(string soundAssetName, object soundAsset, float duration, object userData) { PlaySoundInfo playSoundInfo = (PlaySoundInfo)userData; if (playSoundInfo == null) { throw new GameFrameworkException("Play sound info is invalid."); } if (m_SoundsToReleaseOnLoad.Contains(playSoundInfo.SerialId)) { m_SoundsToReleaseOnLoad.Remove(playSoundInfo.SerialId); 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) { if (m_PlaySoundSuccessEventHandler != null) { m_PlaySoundSuccessEventHandler(this, new PlaySoundSuccessEventArgs(playSoundInfo.SerialId, soundAssetName, soundAgent, duration, playSoundInfo.UserData)); } 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 (m_PlaySoundFailureEventHandler != null) { m_PlaySoundFailureEventHandler(this, new PlaySoundFailureEventArgs(playSoundInfo.SerialId, soundAssetName, playSoundInfo.SoundGroup.Name, playSoundInfo.PlaySoundParams, errorCode.Value, errorMessage, playSoundInfo.UserData)); ReferencePool.Release(playSoundInfo); return; } ReferencePool.Release(playSoundInfo); throw new GameFrameworkException(errorMessage); }
private void LoadSoundFailureCallback(string soundAssetName, LoadResourceStatus status, string errorMessage, object userData) { PlaySoundInfo playSoundInfo = userData as PlaySoundInfo; if (playSoundInfo == null) { throw new GameFrameworkException("Play sound info is invalid."); } string appendErrorMessage = string.Format("Load sound failure, asset name '{0}', status '{1}', error message '{2}'.", soundAssetName, status.ToString(), errorMessage); if (m_PlaySoundFailureEventHandler != null) { m_PlaySoundFailureEventHandler(this, new PlaySoundFailureEventArgs(playSoundInfo.SerialId, soundAssetName, playSoundInfo.SoundGroup.Name, playSoundInfo.PlaySoundParams, PlaySoundErrorCode.LoadAssetFailure, appendErrorMessage, playSoundInfo.UserData)); return; } throw new GameFrameworkException(appendErrorMessage); }
private void LoadSoundSuccessCallback(string soundAssetName, object soundAsset, float duration, object userData) { PlaySoundInfo playSoundInfo = (PlaySoundInfo)userData; if (playSoundInfo == null) { throw new System.Exception("Play sound info is invalid."); } m_SoundsBeingLoaded.Remove(playSoundInfo.SerialId); if (m_SoundsToReleaseOnLoad.Contains(playSoundInfo.SerialId)) { Log.Debug("Release sound '{0}' on loading success.", playSoundInfo.SerialId.ToString()); m_SoundsToReleaseOnLoad.Remove(playSoundInfo.SerialId); m_SoundHelper.ReleaseSoundAsset(soundAsset); return; } PlaySoundErrorCode?errorCode = null; ISoundAgent soundAgent = playSoundInfo.SoundGroup.PlaySound(playSoundInfo.SerialId, soundAsset, playSoundInfo.PlaySoundParams, out errorCode); if (soundAgent != null) { if (m_PlaySoundSuccessEventHandler != null) { m_PlaySoundSuccessEventHandler(this, new PlaySoundSuccessEventArgs(playSoundInfo.SerialId, soundAssetName, soundAgent, duration, playSoundInfo.UserData)); } } else { m_SoundsToReleaseOnLoad.Remove(playSoundInfo.SerialId); m_SoundHelper.ReleaseSoundAsset(soundAsset); string errorMessage = string.Format("Sound group '{0}' play sound '{1}' failure.", playSoundInfo.SoundGroup.Name, soundAssetName); if (m_PlaySoundFailureEventHandler != null) { m_PlaySoundFailureEventHandler(this, new PlaySoundFailureEventArgs(playSoundInfo.SerialId, soundAssetName, playSoundInfo.SoundGroup.Name, playSoundInfo.PlaySoundParams, errorCode.Value, errorMessage, playSoundInfo.UserData)); return; } throw new System.Exception(errorMessage); } }
/// <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); }
public override void Add(TrackLineInfo info) { _info = new PlaySoundInfo(); info.AddNode(_info); }
/// <summary> /// 播放声音 /// </summary> /// <param name="soundAsset">声音资源</param> /// <param name="soundGroupName">声音组名称。</param> /// <param name="priority">加载声音资源的优先级。</param> /// <param name="playSoundParams">播放声音参数。</param> /// <param name="userData">用户自定义数据。</param> /// <returns>声音的序列编号。</returns> /// <exception cref="GameFrameworkException"></exception> public int PlaySound(object soundAsset, 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 = new PlaySoundParams(); } int serialId = m_Serial++; PlaySoundErrorCode?errorCode = null; string errorMessage = null; SoundGroup soundGroup = (SoundGroup)GetSoundGroup(soundGroupName); if (soundGroup == null) { errorCode = PlaySoundErrorCode.SoundGroupNotExist; errorMessage = string.Format("Sound group '{0}' is not exist.", soundGroupName); } else if (soundGroup.SoundAgentCount <= 0) { errorCode = PlaySoundErrorCode.SoundGroupHasNoAgent; errorMessage = string.Format("Sound group '{0}' is have no sound agent.", soundGroupName); } if (errorCode.HasValue) { if (m_PlaySoundFailureEventHandler != null) { m_PlaySoundFailureEventHandler(this, new PlaySoundFailureEventArgs(serialId, soundAsset.ToString(), soundGroupName, playSoundParams, errorCode.Value, errorMessage, userData)); return(serialId); } throw new GameFrameworkException(errorMessage); } m_SoundsBeingLoaded.Add(serialId); var playSoundInfo = new PlaySoundInfo(serialId, soundGroup, playSoundParams, userData); var soundAgent = playSoundInfo.SoundGroup.PlaySound(serialId, soundAsset, playSoundParams, out errorCode); if (soundAgent != null) { if (m_PlaySoundSuccessEventHandler != null) { m_PlaySoundSuccessEventHandler(this, new PlaySoundSuccessEventArgs(serialId, soundAsset.ToString(), soundAgent, 0f, userData)); } } else { m_SoundsToReleaseOnLoad.Remove(serialId); m_SoundHelper.ReleaseSoundAsset(soundAsset); errorMessage = string.Format("Sound group '{0}' play sound asset '{1}' failure.", soundGroupName, soundAsset); if (m_PlaySoundFailureEventHandler != null) { m_PlaySoundFailureEventHandler(this, new PlaySoundFailureEventArgs(serialId, soundAsset.ToString(), soundGroupName, playSoundParams, errorCode.Value, errorMessage, userData)); } else { throw new GameFrameworkException(errorMessage); } } return(serialId); }