# SStateMachine

**成员** 11

|      |                                       |                                                                                                                                              |
| ---- | ------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| 函数 | [NextState](#nextstate)               | Enter the next state                                                                                                                         |
| 函数 | [PrevState](#prevstate)               | –                                                                                                                                            |
| 函数 | [SetState](#setstate)                 | Enters the state of being set that its order is "state"                                                                                      |
| 函数 | [BindToUI](#bindtoui)                 | The state machine will bind itself to all Toggles, Buttons, Dropdowns and Sliders on the SGameObject it is in or on a specified SGameObject. |
| 属性 | [Enabled](#enabled)                   | Whether the simple state machine component is Enabled or not                                                                                 |
| 属性 | [StateCount](#statecount)             | Total number of States.                                                                                                                      |
| 属性 | [StateNames](#statenames)             | A list of the names of all States.                                                                                                           |
| 属性 | [CurrentState](#currentstate)         | The index number of the current state.                                                                                                       |
| 属性 | [CurrentStateName](#currentstatename) | The name of the current state, or null if no state.                                                                                          |
| 属性 | [ComponentName](#componentname)       | The name of this component.                                                                                                                  |
| 属性 | [GameObject](#gameobject)             | The GameObject this component is attached to.                                                                                                |

## 函数

### NextState

void NextState()

Enter the next state

返回值

`void`

示例

**Lua**

```lua
Space.Host.ExecutingObject.StateMachine.NextState()

```

### PrevState

void PrevState()

返回值

`void`

示例

**Lua**

```lua
Space.Host.ExecutingObject.StateMachine.PrevState()

```

### SetState

void SetState(int state)

void SetState(string state)

Enters the state of being set that its order is "state"

参数

| 参数  | 类型   | 说明                                                         |
| ----- | ------ | ------------------------------------------------------------ |
| state | int    | The index of the state. First state is 1.                    |
| state | string | The name of the state as set in the State Machine component. |

返回值

`void`

示例

**Lua**

```lua
Space.Host.ExecutingObject.StateMachine.SetState(2)
--or
Space.Host.ExecutingObject.StateMachine.SetState('A State Name')

```

### BindToUI

void BindToUI()

void BindToUI([SGameObject](/docs/zh-Hans/scripting/client-scripting-api-reference/types/sgameobject.md) go)

The state machine will bind itself to all Toggles, Buttons, Dropdowns and Sliders on the SGameObject it is in or on a specified SGameObject.

Binding to Button : Clicking button will call NextState()<br />Binding to Toggle: Toggle On sets State to 1, Toggle Off sets state to 2<br />Binding to Dropdown: Selecting will set State to that selection's caption text<br />Binding to Slider: Moving slider changes State to slider value

参数

| 参数 | 类型        | 说明                                                          |
| ---- | ----------- | ------------------------------------------------------------- |
| go   | SGameObject | A specific SGameObject which this State Machine will bind to. |

返回值

`void`

示例

**Lua**

```lua
Space.Host.ExecutingObject.StateMachine.BindToUI()
----or
Space.Host.ExecutingObject.StateMachine.BindToUI(Space.Host.GetReference("a reference"))

```

## 属性

### Enabled

bool Enabled {get; set; }

Whether the simple state machine component is Enabled or not

示例

**Lua**

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

```

### StateCount

int StateCount {get; }

Total number of States.

示例

**Lua**

```lua
numberOfStates = Space.Host.ExecutingObject.StateMachine.StateCount

```

### StateNames

string\[] StateNames {get; }

A list of the names of all States.

示例

**Lua**

```lua
tableStateNames = Space.Host.ExecutingObject.StateMachine.StateNames

```

### CurrentState

int CurrentState {get; }

The index number of the current state.

示例

**Lua**

```lua
currentState = Space.Host.ExecutingObject.StateMachine.CurrentState

```

### CurrentStateName

string CurrentStateName {get; }

The name of the current state, or null if no state.

示例

**Lua**

```lua
currentStateName = Space.Host.ExecutingObject.StateMachine.CurrentStateName

```

### ComponentName

string ComponentName {get; }

The name of this component.

示例

**Lua**

```lua
componentName = Space.Host.ExecutingObject.StateMachine.ComponentName

```

### GameObject

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

The GameObject this component is attached to. A component is always attached to a GameObject.

示例

**Lua**

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

```
