56 lines
1.2 KiB
C#
56 lines
1.2 KiB
C#
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 SettingDTO CachedSetting { get; private 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;
|
|
|
|
value += step * Mathf.Sign(direction) * _speed * Time.deltaTime;
|
|
value = Mathf.Clamp(value, minValue, maxValue);
|
|
CachedSetting.FloatValue = value;
|
|
|
|
_slider.SetValue(value);
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|