# 学会 UGUI 之 Slider

The Slider control allows the user to select a numeric value from a predetermined range by dragging the mouse. Note that the similar ScrollBar control is used for scrolling rather than selecting numeric values. Familiar examples include difficulty settings in games and brightness settings in image editors.

滑块控件允许用户通过拖动鼠标从一个预先确定的范围选择一个数字值。熟悉的例子包括在游戏中困难设置和在图像编辑器中亮度设置。

属性:

Fill Rect → The graphic used for the fill area of the control.
用于填充控件的区域的图形。

Handle Rect → The graphic used for the sliding “handle” part of the control
用于控制滑动 “handle” 部分的图形。

Direction → The direction in which the slider’s value will increase when the handle is dragged. The options are Left To Right, Right To Left, Bottom To Top and Top To Bottom.
当拖动句柄时,滑块的值会增加的方向。选项是左到右,右到左,底部到顶部和顶部到底部。

Min Value → The value of the slider when the handle is at its extreme lower end (determined by the Direction property).
句柄在其极端的下端(由方向属性确定)时滑块的值。

Max Value → The value of the slider when the handle is at its extreme upper end (determined by the Direction property).
句柄在其极端的上端(由方向属性确定)时滑块的值。

Whole Numbers → Should the slider be constrained to integer values?
应该限制为整数值滑块吗?

Value → Current numeric value of the slider. If the value is set in the inspector it will be used as the initial value, but this will change at runtime when the value changes.
滑块当前的数值。如果设置的值在inspector中被作为初始值,但在运行时这个值随着更改变为值更改后的值。

事件:

On Value Changed → A UnityEvent that is invoked when the current value of the Slider has changed. The event can send the current value as a float type dynamic argument. The value is passed as a float type regardless of whether the Whole Numbers property is enabled.
当拖动滑块的数字值发生更改时调用。值是响应函数传递的 float 类型,无论是否启用了整个 Whole Numbers 属性。

PS: 滑块的值是由句柄的位置确定的。值从最小值到最大值处理按照拖动的距离的比例增加。默认行为是为滑块以增加从左到右,但使用 Direction 方向属性它也可扭转这种行为。还可以设置滑块以垂直增加通过选择底部到顶部、顶部到底部的方向属性。