internal InputOption(GameObject parentGO, ModSettingInt modSettingInt) : this(parentGO, (ModSetting)modSettingInt) { InputField.SetText(modSettingInt.GetValue().ToString()); InputField.characterValidation = InputField.CharacterValidation.Integer; InputField.AddOnValueChangedEvent(value => { //InputField.SetText(value); if (!long.TryParse(value, out var i)) { i = 0; } if (modSettingInt.maxValue.HasValue && i > modSettingInt.maxValue.Value) { i = modSettingInt.maxValue.Value; } else if (modSettingInt.minValue.HasValue && i < modSettingInt.minValue.Value) { i = modSettingInt.minValue.Value; } modSettingInt.SetValue(i); }); modSettingInt.OnInitialized.InvokeAll(this); Button.AddOnClick(() => { InputField.SetText(modSettingInt.GetDefaultValue().ToString()); }); }
internal SliderOption(GameObject parentGO, ModSettingInt modSettingInt) : this(parentGO, (ModSetting)modSettingInt) { Slider.value = modSettingInt.value; InputField.text = modSettingInt.value.ToString(); Slider.minValue = (long)modSettingInt.minValue; Slider.maxValue = (long)modSettingInt.maxValue; Slider.onValueChanged.AddListener(value => { var l = (long)value; modSettingInt.SetValue(l); if (long.TryParse(InputField.text, out var num) && num != l) { InputField.SetText(l.ToString()); } }); InputField.onValueChanged.AddListener(value => { if (long.TryParse(InputField.text, out var l)) { if (l > modSettingInt.maxValue) { l = (long)modSettingInt.maxValue; } else if (l < modSettingInt.minValue) { l = (long)modSettingInt.minValue; } modSettingInt.SetValue(l); if ((long)Slider.value != l) { Slider.Set(l); } } }); InputField.characterValidation = InputField.CharacterValidation.Integer; Button.AddOnClick(() => { InputField.SetText(modSettingInt.GetDefaultValue().ToString()); }); modSettingInt.OnInitialized.InvokeAll(this); }