Example #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;
        }
Example #2
0
        private void ApplyTheme()
        {
            Color ColorFromTydTable(TydTable table)
            {
                return(new Color(
                           int.Parse(((TydString)table["r"]).Value) / 255.0f,
                           int.Parse(((TydString)table["g"]).Value) / 255.0f,
                           int.Parse(((TydString)table["b"]).Value) / 255.0f,
                           int.Parse(((TydString)table["a"]).Value) / 255.0f));
            }

            var key                 = "UI.ConsoleThemes." + _theme;
            var def                 = (TydTable)StreamingAssetsDatabase.GetDef(key);
            var background          = (TydTable)def["Background"];
            var scrollView          = (TydTable)def["ScrollView"];
            var commandInputField   = (TydTable)def["CommandInputField"];
            var placeholder         = (TydTable)def["Placeholder"];
            var text                = (TydTable)def["Text"];
            var scrollbarBackground = (TydTable)def["ScrollbarBackground"];
            var scrollbarHandle     = (TydTable)def["ScrollbarHandle"];

            _background.color        = ColorFromTydTable(background);
            _scrollView.color        = ColorFromTydTable(scrollView);
            _commandInputField.color = ColorFromTydTable(commandInputField);
            _placeholder.color       = ColorFromTydTable(placeholder);
            _text.color = ColorFromTydTable(text);
            _scrollbarBackground.color = ColorFromTydTable(scrollbarBackground);
            _scrollbarHandle.color     = ColorFromTydTable(scrollbarHandle);
        }
Example #3
0
        public static int CreateAudioSource(string clipKey)
        {
            var source = GameObject.Instantiate(new GameObject()).AddComponent <AudioSource>();
            var clip   = StreamingAssetsDatabase.GetSound(clipKey);

            if (clip == null)
            {
                InGameDebug.Log("Couldn't find clip " + clipKey + ".");
            }
            source.clip            = clip;
            _audioSources[_nextId] = source;
            _unmodifiedAudioSourceVolumes[source] = 1.0f;
            return(_nextId);
        }
Example #4
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());
            });
        }
Example #5
0
        public static void Set(int id, string key, DynValue value)
        {
            if (!_audioSources.ContainsKey(id))
            {
                InGameDebug.Log("SoundManager.Set(): No AudioSource with id " + id + ".");
                return;
            }
            var audioSource = _audioSources[id];

            switch (key.ToLower())
            {
            case "clip":
                audioSource.clip = StreamingAssetsDatabase.GetSound(value.String);
                break;

            case "loop":
                audioSource.loop = value.Boolean;
                break;

            case "volume":
                _unmodifiedAudioSourceVolumes[audioSource] = (float)value.Number;
                if (_musicSources.ContainsKey(id))
                {
                    audioSource.volume = _unmodifiedAudioSourceVolumes[audioSource] * _musicVolume;
                }
                if (_musicSources.ContainsKey(id))
                {
                    audioSource.volume = _unmodifiedAudioSourceVolumes[audioSource] * _effectsVolume;
                }
                break;

            case "pitch":
                audioSource.pitch = (float)value.Number;
                break;

            case "mute":
                audioSource.mute = value.Boolean;
                break;

            case "time":
                audioSource.time = (float)value.Number;
                break;
            }
        }
Example #6
0
        public static void SetImage(int id, string key)
        {
            var go    = ObjectBuilder.Get(id);
            var image = go.GetComponentInChildren <Image>();

            if (image == null)
            {
                image = go.AddComponent <Image>();
            }
            if (key == null)
            {
                image.sprite = null;
            }
            else
            {
                var texture = StreamingAssetsDatabase.GetTexture(key);
                image.sprite = Sprite.Create(
                    texture,
                    new Rect(0, 0, texture.width, texture.height),
                    new Vector2(0.5f, 0.5f)
                    );
            }
        }
Example #7
0
        public static void SetTexture(int id, string textureKey)
        {
            var go = Get(id);
            var sr = go.GetComponentInChildren <SpriteRenderer>();

            if (sr == null)
            {
                sr = go.AddComponent <SpriteRenderer>();
            }
            if (textureKey == null)
            {
                sr.sprite = null;
            }
            else
            {
                var texture = StreamingAssetsDatabase.GetTexture(textureKey);
                sr.sprite = Sprite.Create(
                    texture,
                    new Rect(0, 0, texture.width, texture.height),
                    new Vector2(0.5f, 0.5f)
                    );
            }
        }