Пример #1
0
        internal InputOption(GameObject parentGO, ModSettingDouble modSettingDouble) : this(parentGO, (ModSetting)modSettingDouble)
        {
            InputField.SetText($"{Math.Round((double)modSettingDouble.GetValue(), 5):0.#####}");

            InputField.characterValidation = InputField.CharacterValidation.Decimal;
            InputField.AddOnValueChangedEvent(value =>
            {
                //InputField.SetText(value);
                if (!double.TryParse(value, out var d))
                {
                    d = 0;
                }
                if (modSettingDouble.maxValue.HasValue && d > modSettingDouble.maxValue.Value)
                {
                    d = (int)modSettingDouble.maxValue.Value;
                }
                else if (modSettingDouble.minValue.HasValue && d < modSettingDouble.minValue.Value)
                {
                    d = (int)modSettingDouble.minValue.Value;
                }
                modSettingDouble.SetValue(d);
            });
            modSettingDouble.OnInitialized.InvokeAll(this);
            Button.AddOnClick(() =>
            {
                InputField.SetText($"{Math.Round((double)modSettingDouble.GetDefaultValue(), 5):0.#####}");
            });
        }
Пример #2
0
        internal SliderOption(GameObject parentGO, ModSettingDouble modSettingDouble) : this(parentGO, (ModSetting)modSettingDouble)
        {
            Slider.value    = (float)modSettingDouble.value;
            InputField.text = modSettingDouble.value.ToString("");
            Slider.minValue = (float)modSettingDouble.minValue;
            Slider.maxValue = (float)modSettingDouble.maxValue;

            Slider.onValueChanged.AddListener(value =>
            {
                var d = (double)value;
                modSettingDouble.SetValue(d);
                if (double.TryParse(InputField.text, out var num) && Math.Abs(num - d) > .001)
                {
                    InputField.SetText($"{Math.Round(d, 5):0.#####}");
                }
            });

            InputField.onValueChanged.AddListener(value =>
            {
                if (double.TryParse(InputField.text, out var d))
                {
                    if (d > modSettingDouble.maxValue)
                    {
                        d = (double)modSettingDouble.maxValue;
                    }
                    else if (d < modSettingDouble.minValue)
                    {
                        d = (double)modSettingDouble.minValue;
                    }
                    modSettingDouble.SetValue(d);
                    if (Math.Abs(Slider.value - d) > .001)
                    {
                        Slider.Set(Convert.ToSingle(d));
                    }
                }
            });
            InputField.characterValidation = InputField.CharacterValidation.Decimal;


            Button.AddOnClick(() =>
            {
                InputField.SetText(modSettingDouble.GetDefaultValue().ToString());
            });


            modSettingDouble.OnInitialized.InvokeAll(this);
        }