using UnityEngine; public class FloatView : BaseSettingView { [SerializeField] private MSlider _slider; [SerializeField] private float _speed = 10; private float minValue; private float maxValue; private float value; private float delta; private float step; public override SettingDTO CachedSetting { get; set; } public override void Initialize(SettingDTO setting) { base.Initialize(setting); CachedSetting = setting; CacheSettingValues(setting); Display(); } public override void TakeInput(int direction, bool _) { if (direction == 0) return; var newValue = value + step * Mathf.Sign(direction) * _speed * Time.deltaTime; newValue = Mathf.Clamp(newValue, minValue, maxValue); if (newValue != value) { value = newValue; _slider.SetValue(value); CachedSetting.FloatValue = value; SettingsManager.TriggerSettingsChanged(); } } private void Display() { float percent = (value - minValue) / delta; _slider.SetValue(percent); } private void CacheSettingValues(SettingDTO setting) { minValue = setting.FloatMin; maxValue = setting.FloatMax; step = setting.FloatStep; value = setting.FloatValue; delta = maxValue - minValue; } }