# SUISlider

**成员** 15

|      |                                       |                                                                                                          |
| ---- | ------------------------------------- | -------------------------------------------------------------------------------------------------------- |
| 函数 | [OnValueChanged](#onvaluechanged)     | Callback executed when the value of the slider is changed.                                               |
| 属性 | [Enabled](#enabled)                   | Whether this Slider component is Enabled or not                                                          |
| 属性 | [Interactable](#interactable)         | Use to enable or disable the ability to interact with the slider.                                        |
| 属性 | [Direction](#direction)               | The direction of the slider (0 to 4). 0 Left To Right, 1 Right To Left, 2 Bottom To Top, 3 Top To Bottom |
| 属性 | [MinValue](#minvalue)                 | The minimum allowed value of the slider.                                                                 |
| 属性 | [MaxValue](#maxvalue)                 | The maximum allowed value of the slider.                                                                 |
| 属性 | [WholeNumbers](#wholenumbers)         | Should the value only be allowed to be whole numbers?                                                    |
| 属性 | [Value](#value)                       | The current value of the slider.                                                                         |
| 属性 | [NormalizedValue](#normalizedvalue)   | The current value of the slider normalized into a value between 0 and 1.                                 |
| 属性 | [NormalColor](#normalcolor)           | The normal color.                                                                                        |
| 属性 | [HighlightedColor](#highlightedcolor) | The color of the control when it is highlighted.                                                         |
| 属性 | [PressedColor](#pressedcolor)         | The color of the control when it is pressed.                                                             |
| 属性 | [DisabledColor](#disabledcolor)       | The color of the control when it is disabled.                                                            |
| 属性 | [ColorMultiplier](#colormultiplier)   | This multiplies the tint color for each transition by its value.                                         |
| 属性 | [GameObject](#gameobject)             | –                                                                                                        |

## 函数

### OnValueChanged

void OnValueChanged(Closure callback)

Callback executed when the value of the slider is changed.

参数

| 名称     | 类型    | 默认值 |
| -------- | ------- | ------ |
| callback | Closure | –      |

返回值

`void`

示例

**Lua**

```lua
function ValueChanged()
--
end

Space.Host.ExecutingObject.UISlider.OnValueChanged(ValueChanged)

```

**Lua**

```lua
--This script will make moving a slider control the Master Volume
--and also update a text field with the current Master Volume
--[You need to add the slider and text field as a reference]

slider = Space.Host.GetReference("Slider").UISlider
textField = Space.Host.GetReference("Text Field").UIText


OnValueChanged = function()
Space.UI.MasterVolume = slider.NormalizedValue * 100
textField.Text = Space.UI.MasterVolume
end

slider.OnValueChanged(OnValueChanged)

```

## 属性

### Enabled

bool Enabled {get; set; }

Whether this Slider component is Enabled or not

示例

**Lua**

```lua
Space.Host.ExecutingObject.UISlider.Enabled = false 

```

**Lua**

```lua
--clicking this object will toggle a Sliders's Enabled status

thisGameObject = Space.Host.ExecutingObject
slider = Space.Host.GetReference("slider").UISlider 
--make sure to add this reference to the Scripting Runtime component


OnClick = function()
slider.Enabled =  not slider.Enabled
end


thisGameObject.AddClickable()
thisGameObject.Clickable.OnClick(OnClick)

```

### Interactable

bool Interactable {get; set; }

Use to enable or disable the ability to interact with the slider.

示例

**Lua**

```lua
Space.Host.ExecutingObject.UISlider.Interactable = true

```

**Lua**

```lua
--clicking this object will toggle a Sliders's Interactable status

thisGameObject = Space.Host.ExecutingObject
slider = Space.Host.GetReference("slider").UISlider 
--make sure to add this reference to the Scripting Runtime component


OnClick = function()
slider.Interactable =  not slider.Interactable
end


thisGameObject.AddClickable()
thisGameObject.Clickable.OnClick(OnClick)

```

### Direction

int Direction {get; set; }

The direction of the slider (0 to 4). 0 Left To Right, 1 Right To Left, 2 Bottom To Top, 3 Top To Bottom

示例

**Lua**

```lua
Space.Host.ExecutingObject.UISlider.Direction = 1

```

### MinValue

float MinValue {get; set; }

The minimum allowed value of the slider.

示例

**Lua**

```lua
Space.Host.ExecutingObject.UISlider.MinValue = 10

```

### MaxValue

float MaxValue {get; set; }

The maximum allowed value of the slider.

示例

**Lua**

```lua
Space.Host.ExecutingObject.UISlider.MaxValue = 20

```

### WholeNumbers

bool WholeNumbers {get; set; }

Should the value only be allowed to be whole numbers?

示例

**Lua**

```lua
Space.Host.ExecutingObject.UISlider.WholeNumbers = true

```

**Lua**

```lua
--clicking this object will toggle a Sliders's Whole Numbers status

thisGameObject = Space.Host.ExecutingObject
slider = Space.Host.GetReference("slider").UISlider 
--make sure to add this reference to the Scripting Runtime component


OnClick = function()
slider.WholeNumbers =  not slider.WholeNumbers
end


thisGameObject.AddClickable()
thisGameObject.Clickable.OnClick(OnClick)

```

### Value

float Value {get; set; }

The current value of the slider.

示例

**Lua**

```lua
Space.Host.ExecutingObject.UISlider.Value = 20

```

### NormalizedValue

float NormalizedValue {get; set; }

The current value of the slider normalized into a value between 0 and 1.

示例

**Lua**

```lua
Space.Host.ExecutingObject.UISlider.NormalizedValue = 0.5

```

**Lua**

```lua
--This script will make moving a slider control the Master Volume
--and also update a text field with the current Master Volume
--(example: custom UI)
--[You need to add the slider and text field as a reference]

slider = Space.Host.GetReference("Slider").UISlider
textField = Space.Host.GetReference("Text Field").UIText


OnValueChanged = function()
Space.UI.MasterVolume = slider.NormalizedValue * 100
textField.Text = Space.UI.MasterVolume
end

slider.OnValueChanged(OnValueChanged)

```

### NormalColor

[SColor](/docs/zh-Hans/scripting/client-scripting-api-reference/types/scolor.md) NormalColor {get; set; }

The normal color.

示例

**Lua**

```lua
Space.Host.ExecutingObject.UISlider.NormalColor = Color.Red

```

### HighlightedColor

[SColor](/docs/zh-Hans/scripting/client-scripting-api-reference/types/scolor.md) HighlightedColor {get; set; }

The color of the control when it is highlighted.

示例

**Lua**

```lua
Space.Host.ExecutingObject.UISlider.HighlightedColor = Color.Red

```

### PressedColor

[SColor](/docs/zh-Hans/scripting/client-scripting-api-reference/types/scolor.md) PressedColor {get; set; }

The color of the control when it is pressed.

示例

\`\`\` Space.Host.ExecutingObject.UISlider.PressedColor = Color.Red \`\`\`

### DisabledColor

[SColor](/docs/zh-Hans/scripting/client-scripting-api-reference/types/scolor.md) DisabledColor {get; set; }

The color of the control when it is disabled.

示例

**Lua**

```lua
lSpace.Host.ExecutingObject.UISlider.DisabledColor = Color.Red

```

### ColorMultiplier

float ColorMultiplier {get; set; }

This multiplies the tint color for each transition by its value.

示例

**Lua**

```lua
Space.Host.ExecutingObject.UISlider.ColorMultiplier = 1.2

```

### GameObject

[SGameObject](/docs/zh-Hans/scripting/client-scripting-api-reference/types/sgameobject.md) GameObject {get; }

示例

**Lua**

```lua
theGameObject = Space.Host.ExecutingObject.UISlider.GameObject

```
