Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cesardeazevedo/Unity-Component-State-Machine
Simple Unity State Machine designed with components
https://github.com/cesardeazevedo/Unity-Component-State-Machine
Last synced: 3 months ago
JSON representation
Simple Unity State Machine designed with components
- Host: GitHub
- URL: https://github.com/cesardeazevedo/Unity-Component-State-Machine
- Owner: cesardeazevedo
- License: mit
- Created: 2015-04-17T00:41:18.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-04-24T05:01:33.000Z (over 9 years ago)
- Last Synced: 2024-04-22T08:38:35.913Z (7 months ago)
- Language: C#
- Homepage:
- Size: 223 KB
- Stars: 5
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Unity-Component-State-Machine
A Simple Unity State Machine designed with components
![screenshot](http://i.cubeupload.com/PXhCZo.png)
#How to use
1. Declare the initial states, and initialize them.
```c#
///
///Player.cs
///
public class Player : GameStateMachine
{
///
/// Make sure that the name of these states are the same name of the script component
///
public enum States {
State1,
State2,
State3
}void Awake() {
base.Initialize();
}
void Start() {
ChangeState(State.State2);
}
}
```##Components
Each state, is an individual component, and have to be attached to the same GameObject (for now), and they are optional
```c#
///
/// State1.cs
///
public class State1 : StateComponentBase
{public override void Awake()
{
base.Awake();
}
public override void EnterState() { }
public override void ExitState() { }
}
```##Properties
####Behaviour
The base component reference.####NextState
Enum which represent the next state will come, only in the event `ExitState()`.####IsActive
A bool which represent whether the current state is active or not.```c#
//State1.cs
void Update() {
if(IsActive) {
//The State1 is active
}
}
```##Events
####EnterState()
- Emitted whenever `ChangeState()` is invoked to current state.
####ExitState()
- Emitted whenever `ChangeState()` is invoked to other state.
##Change States
You can change the states easily
* From Base Behaviour
```c#
//Player.cs
public void Start() {
base.ChangeState(States.State2)
}
```* From Components
```c#
//State2.cs
public void Start() {
Behaviour.ChangeState(Player.States.State3);
}
```#Contributing
1. Fork it!
2. Create your feature branch: git checkout -b my-new-feature
3. Commit your changes: git commit -m 'Add some feature'
4. Push to the branch: git push origin my-new-feature
5. Submit a pull request :D#License
[MIT](./LICENSE)