Exemplo n.º 1
0
    /// <summary>
    /// Set key value
    /// </summary>
    /// <param name="value">The value of the key to set</param>
    public void SetValue(KeyCode value)
    {
        this.value = value;

        // Update button display values
        SetButtonDisplay(GetKeyDisplay(value));

        // Call settings panel controller KeyElementValueChanged and OnElementValueChanged functions
        settingsPanelController.KeyElementValueChanged();
        settingsPanelController.OnElementValueChanged();
    }
    // -------------------

    private void Awake()
    {
        slider     = transform.Find("Slider").GetComponent <Slider>();
        inputField = transform.Find("InputField").GetComponent <InputField>();

        // If slider type is an int
        if (sliderType == SliderType.Integer)
        {
            // Parse maxValue to an int
            maxValue = (int)maxValue;
        }

        // Maximum value cannot be 0
        if (maxValue == 0)
        {
            Debug.LogWarning("maxValue cannot be 0 (in " + gameObject.name + " sliderElement)");
        }

        // Set inputField contentType
        if (sliderType == SliderType.Integer)
        {
            inputField.contentType = InputField.ContentType.IntegerNumber;
        }
        else if (sliderType == SliderType.Float)
        {
            inputField.contentType = InputField.ContentType.DecimalNumber;
        }

        // Set inputField character limit
        inputField.characterLimit = maxValue.ToString().Length + 1;

        // Set listeners
        slider.onValueChanged.AddListener(SliderValueChanged);
        inputField.onValueChanged.AddListener(InputFieldValueChanged);

        // Set value to default value
        SetValue(defaultValue);

        // Add value changed listener
        SettingsPanelController settingsPanelController = GameObject.Find("UI").transform.Find("MenuCanvas/Panels/Settings").GetComponent <SettingsPanelController>();

        slider.onValueChanged.AddListener((x) => settingsPanelController.OnElementValueChanged());
    }
    // -------------------

    private void Awake()
    {
        dropdown = transform.Find("Dropdown").GetComponent <Dropdown>();

        // Set dropdown options
        dropdown.ClearOptions();
        dropdown.AddOptions(options);

        // Set label text to defaultValue
        transform.Find("Dropdown/Label").GetComponent <Text>().text = options[defaultValue];

        // Set value to default value
        SetValue(defaultValue);

        // Add value changed listener
        SettingsPanelController settingsPanelController = GameObject.Find("UI").transform.Find("MenuCanvas/Panels/Settings").GetComponent <SettingsPanelController>();

        dropdown.onValueChanged.AddListener((x) => settingsPanelController.OnElementValueChanged());
    }