Example #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);
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Загрузить пакеты ресурсов со звуковыми эффектами. Предназначен для вызова после инициализации
        /// </summary>
        public void LoadSfxPacks()
        {
            UnloadSfxPacks();
            foreach (var appSoundAssetPair in CurrentAudioLibrary.SoundEffects)
            {
                LinkedResourceManager.GetAssetInfo(appSoundAssetPair.Value.LinkedAssetMetadata, out string assetPackName,
                                                   out string assetName);

                if (!LoadedSfxAssetPacks.Contains(assetPackName))
                {
                    LoadedSfxAssetPacks.Add(assetPackName);
                    LinkedResourceManager.LoadAssetPack(assetPackName);
                }
            }
        }