コード例 #1
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);
                    }
                }
            }
        }
コード例 #2
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);
         }
     }
 }