using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems; using System; namespace UIWidgets { /// /// Range slider. /// [AddComponentMenu("UI/UIWidgets/RangeSlider")] public class RangeSlider : RangeSliderBase { /// /// Value to position. /// /// Position. /// Value. protected override float ValueToPosition(int value) { var points_per_unit = FillSize() / (limitMax - limitMin); return points_per_unit * (InBounds(value) - limitMin) + GetStartPoint(); } /// /// Position to value. /// /// Value. /// Position. protected override int PositionToValue(float position) { var points_per_unit = FillSize() / (limitMax - limitMin); var value = position / points_per_unit + LimitMin; if (WholeNumberOfSteps) { return InBounds(Mathf.RoundToInt(value / step) * step); } else { return InBounds(Mathf.RoundToInt(value)); } } /// /// Position range for minimum handle. /// /// The position limits. protected override Vector2 MinPositionLimits() { return new Vector2(ValueToPosition(LimitMin), ValueToPosition(valueMax - step)); } /// /// Position range for maximum handle. /// /// The position limits. protected override Vector2 MaxPositionLimits() { return new Vector2(ValueToPosition(valueMin + step), ValueToPosition(limitMax)); } /// /// Fit value to bounds. /// /// Value. /// Value. protected override int InBounds(int value) { return Mathf.Clamp(value, limitMin, limitMax); } /// /// Fit minumum value to bounds. /// /// Value. /// Value. protected override int InBoundsMin(int value) { return Mathf.Clamp(value, limitMin, valueMax - step); } /// /// Fit maximum value to bounds. /// /// Value. /// Value. protected override int InBoundsMax(int value) { return Mathf.Clamp(value, valueMin + step, valueMax); } /// /// Increases the minimum value. /// protected override void IncreaseMin() { ValueMin += step; } /// /// Decreases the minimum value. /// protected override void DecreaseMin() { ValueMin -= step; } /// /// Increases the maximum value. /// protected override void IncreaseMax() { ValueMax += step; } /// /// Decreases the maximum value. /// protected override void DecreaseMax() { ValueMax -= step; } } }