/// <summary> /// Начать воспроизведение фоновой музыки /// </summary> /// <param name="parMusicAsset">Тип фоновой музыки</param> /// <param name="parIsLooped">Зациклить воспроизведение?</param> public void PlayBgMusic(EAppMusicAssets parMusicAsset, bool parIsLooped) { //выгрузим старый ресурс фоновой музыки if (PlayingBackgroundMusic != null) { AppSoundManagerMediator.Send( new SoundManagerMessage(ESoundManagerMessageType.SoundReset, PlayingBackgroundMusic.LinkedAppSoundAsset), AppSoundManagerMediator.ViewSoundManagerColleague); while (true) { SoundManagerRequestB requestBIsPlaying = new SoundManagerRequestB(ESoundManagerRequestType.IsSoundPlaying, PlayingBackgroundMusic.LinkedAppSoundAsset); AppSoundManagerMediator.Request(requestBIsPlaying, AppSoundManagerMediator.ViewSoundManagerColleague); if (!requestBIsPlaying.RequestDataBool) { break; } } LinkedResourceManager.GetAssetInfo(PlayingBackgroundMusic.LinkedAppSoundAsset.LinkedAssetMetadata, out string assetPackName, out string assetName); if (assetPackName != null && assetName != null) { //выгрузка LinkedResourceManager.UnloadAssetPack(assetPackName); } } if (ActualAppModel.GetGameplaySettingsData().IsMusicEnabled) { //загружаемый новый ресурс фоновой музыки if (CurrentAudioLibrary.Music.TryGetValue(parMusicAsset, out AppSoundAsset soundAsset)) { LinkedResourceManager.GetAssetInfo(soundAsset.LinkedAssetMetadata, out string assetPackName, out string assetName); if (assetPackName != null && assetName != null) { //загрузка LinkedResourceManager.LoadAssetPack(assetPackName); //воспроизведение AppSoundManagerMediator.Send( new SoundManagerMessageB(ESoundManagerMessageType.SoundPlay, soundAsset, parIsLooped), AppSoundManagerMediator.ViewSoundManagerColleague); PlayingBackgroundMusic = new PlayingBackgroundMusicData(soundAsset, parMusicAsset); } } } }
/// <summary> /// Проигрывается ли сейчас фоновая музыка? /// </summary> /// <returns>True, если проигрывается</returns> public bool IsMusicPlaying() { if (PlayingBackgroundMusic == null) { return(false); } SoundManagerRequestB requestBMusicIsPlaying = new SoundManagerRequestB(ESoundManagerRequestType.IsSoundPlaying, PlayingBackgroundMusic.LinkedAppSoundAsset); AppSoundManagerMediator.Request(requestBMusicIsPlaying, AppSoundManagerMediator.ViewSoundManagerColleague); return(requestBMusicIsPlaying.RequestDataBool); }
/// <summary> /// Обновление данных менеджера. Предназначен для вызова каждый кадр в модели. /// </summary> public void ManagerUpdateStep() { //обновление состояния проигрывания звуковых эффектов for (var i = 0; i < PlayingSfx.Count; i++) { AppSoundAsset appSoundAsset = PlayingSfx[i]; //используем запросы для получения данных SoundManagerRequestB requestBIsPlaying = new SoundManagerRequestB(ESoundManagerRequestType.IsSoundPlaying, appSoundAsset); AppSoundManagerMediator.Request(requestBIsPlaying, AppSoundManagerMediator.ViewSoundManagerColleague); SoundManagerRequestB requestBIsPaused = new SoundManagerRequestB(ESoundManagerRequestType.IsSoundPaused, appSoundAsset); AppSoundManagerMediator.Request(requestBIsPaused, AppSoundManagerMediator.ViewSoundManagerColleague); if (!requestBIsPlaying.RequestDataBool && !requestBIsPaused.RequestDataBool) { PlayingSfx.Remove(appSoundAsset); i--; } } }
/// <summary> /// Вспомогательный метод для проверки приостановки воспроизведения аудио ресурса /// </summary> /// <param name="parAppSoundAsset">Целевой аудио ресурс для проверки</param> /// <returns>True, если воспроизведение приостановлено</returns> public bool IsSoundPaused(AppSoundAsset parAppSoundAsset) { SoundManagerRequestB request = new SoundManagerRequestB(ESoundManagerRequestType.IsSoundPaused, parAppSoundAsset); return(request.RequestDataBool); }