コード例 #1
0
 /// <summary>
 /// Стандартный конструктор
 /// </summary>
 /// <param name="parResourceManager">Менеджер ресурсов</param>
 /// <param name="parModel">Модель</param>
 public AppSoundManager(ResourceManager parResourceManager, IAppModel parModel)
 {
     AppSoundManagerMediator = new AppSoundManagerMediator(parResourceManager);
     AppSoundManagerMediator.MainAppSoundManagerColleague =
         AppSoundManagerColleague = new AppSoundManagerColleague(AppSoundManagerMediator);
     ActualAppModel = parModel;
 }
コード例 #2
0
 /// <summary>
 /// Возобновить воспроизведение всех звуковых эффектов
 /// </summary>
 public void ResumeAllSfxSounds()
 {
     foreach (var appSoundAsset in PlayingSfx)
     {
         AppSoundManagerMediator.Send(new SoundManagerMessage(ESoundManagerMessageType.SoundPause, appSoundAsset),
                                      AppSoundManagerMediator.ViewSoundManagerColleague);
     }
 }
コード例 #3
0
        /// <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);
                    }
                }
            }
        }
コード例 #4
0
        /// <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);
        }
コード例 #5
0
 /// <summary>
 /// Воспроизвести звуковой эффект
 /// </summary>
 /// <param name="parSfxAsset">Тип звукового эффекта</param>
 /// <param name="parIsLooped">Зациклить воспроизведение?</param>
 public void PlaySfx(EAppSfxAssets parSfxAsset, bool parIsLooped)
 {
     //play sound
     if (ActualAppModel.GetGameplaySettingsData().IsSfxEnabled)
     {
         if (CurrentAudioLibrary.SoundEffects.TryGetValue(parSfxAsset, out AppSoundAsset soundAsset))
         {
             AppSoundManagerMediator.Send(
                 new SoundManagerMessage(ESoundManagerMessageType.SoundPlay, soundAsset),
                 AppSoundManagerMediator.ViewSoundManagerColleague);
             PlayingSfx.Add(soundAsset);
         }
     }
 }
コード例 #6
0
        /// <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--;
                }
            }
        }
コード例 #7
0
 /// <summary>
 /// Вспомогательный метод для остановки воспроизведения аудио ресурса
 /// </summary>
 /// <param name="parAppSoundAsset">Целевой аудио ресурс</param>
 public void StopSound(AppSoundAsset parAppSoundAsset)
 {
     AppSoundManagerMediator.Send(new SoundManagerMessage(ESoundManagerMessageType.SoundStop, parAppSoundAsset),
                                  AppSoundManagerMediator.ViewSoundManagerColleague);
 }