Exemplo n.º 1
0
    void Start()
    {
        gameManager       = GameObject.Find("GameManager");
        gameConfigManager = gameManager.GetComponent <GameConfigManager>();

        var valueFromConfig = gameConfigManager.GetType().GetProperty(affectedVariable).GetValue(gameConfigManager, null);

        if (valueFromConfig is int)
        {
            slider.value        = (int)valueFromConfig;
            slider.wholeNumbers = true;
            _isInt        = true;
            rowTitle.text = CamelCaseToTitleCase(affectedVariable) + " : " + slider.value;
        }
        else
        {
            slider.value  = (float)valueFromConfig;
            rowTitle.text = CamelCaseToTitleCase(affectedVariable) + " : " + slider.value.ToString("0.00");
        }

        string constCase = CamelCaseToConstCase(affectedVariable);

        slider.onValueChanged.AddListener(delegate { OnSliderWasChanged(); });

        float minValue = (float)gameConfigManager.GetType().GetField("MIN_" + constCase).GetValue(gameConfigManager);
        float maxValue = (float)gameConfigManager.GetType().GetField("MAX_" + constCase).GetValue(gameConfigManager);

        slider.minValue = minValue;
        slider.maxValue = maxValue;
    }
Exemplo n.º 2
0
 public void OnSliderWasChanged()
 {
     if (_isInt)
     {
         gameConfigManager.GetType().GetProperty(affectedVariable).SetValue(gameConfigManager, (int)slider.value);
         rowTitle.text = CamelCaseToTitleCase(affectedVariable) + " : " + slider.value;
     }
     else
     {
         gameConfigManager.GetType().GetProperty(affectedVariable).SetValue(gameConfigManager, slider.value);
         rowTitle.text = CamelCaseToTitleCase(affectedVariable) + " : " + slider.value.ToString("0.00");
     }
 }