Esempio n. 1
0
        public static void Initialize()
        {
            if (_initialized)
            {
                return;
            }
            StreamingAssetsDatabase.AddOnSettingChangedListener("musicVolume", v =>
            {
                var oldVolume = _musicVolume;
                var newVolume = float.Parse(v);
                _musicVolume  = newVolume;
                foreach (var source in _musicSources.Values)
                {
                    source.volume = _unmodifiedAudioSourceVolumes[source] * _musicVolume;
                }
            });
            StreamingAssetsDatabase.AddOnSettingChangedListener("effectsVolume", v =>
            {
                var oldVolume  = _effectsVolume;
                var newVolume  = float.Parse(v);
                _effectsVolume = newVolume;
                foreach (var source in _effectSources.Values)
                {
                    source.volume = _unmodifiedAudioSourceVolumes[source] * _effectsVolume;
                }
            });

            _musicVolume   = float.Parse(StreamingAssetsDatabase.GetSetting("musicVolume"));
            _effectsVolume = float.Parse(StreamingAssetsDatabase.GetSetting("effectsVolume"));
            _initialized   = true;
        }
Esempio n. 2
0
        /// <summary>
        /// Sets the settings key that the slider will read from/write to.
        /// </summary>
        /// <param name="settingKey">The setting key.</param>
        public void SetKey(string settingKey)
        {
            var value = StreamingAssetsDatabase.GetSetting(settingKey);
            var parts = settingKey.Split(new char[] { '.' });

            _keyText.text   = parts[parts.Length - 1];
            _valueText.text = value;
            _slider.value   = float.Parse(value);
            _slider.onValueChanged.AddListener(v =>
            {
                _valueText.text = v.ToString();
                StreamingAssetsDatabase.AddSettingToBeChanged(settingKey, v.ToString());
            });
        }