示例#1
0
        private void SoundPackChanged(ISound sound, string audioFileName, UISlider uiSlider)
        {
            var configuration = Mod.Instance.Settings.GetSoundsByCategoryId <string>(sound.CategoryId);

            // Selected audio changed
            if (!configuration.ContainsKey(sound.Id))
            {
                configuration.Add(sound.Id, new ConfigurationV4.Sound());
            }

            // Set preset to custom
            if (!this.isChangingSoundPackPreset)
            {
                this.soundPackPresetDropDown.selectedIndex = 1;
            }

            if (!string.IsNullOrEmpty(audioFileName))
            {
                // Chosen audio is a custom audio
                configuration[sound.Id].SoundPack = audioFileName;
                var audioFile = SoundPacksManager.instance.GetAudioFileByName(sound.CategoryId, sound.Id, audioFileName);

                if (LoadingManager.instance.m_loadingComplete || !sound.IngameOnly)
                {
                    sound.PatchSound(audioFile);
                }
                else
                {
                    Mod.Instance.Log.Debug("Skip patching sound of {0}.{1} as there isn't a game active", sound.CategoryId, sound.Id);
                }

                uiSlider.maxValue = Mathf.Max(audioFile.AudioInfo.MaxVolume, audioFile.AudioInfo.Volume);
                uiSlider.value    = audioFile.AudioInfo.Volume;
            }
            else
            {
                // Chosen audio is the default one
                configuration[sound.Id].SoundPack = "";

                if (LoadingManager.instance.m_loadingComplete || !sound.IngameOnly)
                {
                    sound.RevertSound();
                }
                else
                {
                    Mod.Instance.Log.Debug("Skip reverting sound of {0}.{1} as there isn't a game active", sound.CategoryId, sound.Id);
                }

                uiSlider.maxValue = sound.MaxVolume;
                uiSlider.value    = sound.DefaultVolume;
            }
            Mod.Instance.Log.Debug("Saving config");
            Mod.Instance.Settings.SaveConfig(Mod.Instance.SettingsFilename);
        }