Comments (3)
new StateMachine() PlayerState is enum
from unityhfsm.
This feature is currently fully supported by UnityHFSM but not documented yet.
Every nested state machine can use its own type for the state identifiers. The only thing that all state machines in a given hierarchy have to share, is the type for the triggers / events, so that they can be passed down the hierarchy.
The StateMachine
class takes 3 generic type parameters: TOwnId
, TStateId
and TEvent
. TStateId
is the type for the state names in a state machine, i.e. of its child states. If you use a state machine as a state (-> it would be a nested state machine), it itself needs an identifier for the parent state machine. This is the TOwnId
type parameter. Lastly TEvent
is the type for the triggers and events.
There are also multiple overloads for the StateMachine
class that reduce the boilerplate code needed to get started:
-
StateMachine
=StateMachine<string, string, string>
-
StateMachine<T>
=StateMachine<T, T, string>
-
StateMachine<T1, T2>
=StateMachine<T1, T1, T2>
Here's a small example that shows how you can mix different types:
enum PlayerStates {
IDLE, MOVE, JUMP
}
enum MoveStates {
WALK, DASH
}
enum Events {
ON_DAMAGE, ON_WIN
}
var fsm = new StateMachine<PlayerStates, Events>();
var moveFsm = new StateMachine<PlayerStates, MoveStates, Events>();
var idleFsm = new StateMachine<PlayerStates, string, Events>();
fsm.AddState(PlayerStates.IDLE, idleFsm);
fsm.AddState(PlayerStates.MOVE, moveFsm);
fsm.AddState(PlayerStates.JUMP, new State<PlayerStates, Events>());
// Or simply using shortcut methods: fsm.AddState(PlayerStates.JUMP);
moveFsm.AddState(MoveStates.WALK);
moveFsm.AddState(MoveStates.DASH);
moveFsm.AddTransition(new Transition<MoveStates>(MoveStates.WALK, MoveStates.DASH));
// Or simply: fsm.AddTransition(MoveStates.WALK, MoveStates.DASH);
idleFsm.AddState("Animation 1", new State<string, Events>());
idleFsm.AddState("Animation 2");
// ...
Does this solve your problem?
from unityhfsm.
Yes, perfect! I wasn't able to figure out what the other type parameters were and I think the overloads confused me. But got it working with this example! Might be useful to pop this into the docs.
Had another quick question #15 if you have a minute I would really appreciate it!
from unityhfsm.
Related Issues (20)
- Feature request: onEnter and onExit on non-root StateMachines HOT 2
- feature request: OnActiveStateChanged event? HOT 5
- Feature request: add OnTransition callback to Transition class HOT 9
- Name of Test asmdef can conflict with project HOT 1
- StateMachine<T> and StateMachine needs a common StateMachine base type HOT 6
- How to return to the previous sub-state of a Hierarchical FSM? (2.0) HOT 2
- Is there a StateChanged changed event for when any transition occurs, even a sub-machine one? HOT 3
- Trigger/Action should use a separate type
- Documentation request: Explain what HybridStateMachine is HOT 1
- Sample code can not compile in version 2.0 HOT 2
- Mention Support for Generic State Identifiers Higher Up in README HOT 1
- How to visualize multi-layer state machines HOT 1
- How to use AddTransition in two different TStateId based by enum? HOT 1
- [Question] Any node editor for UnityHfsm?Or other Editor Tool ? HOT 1
- [Question] Support for parallel states HOT 2
- Perform logic in FixedUpdate or LateUpdate?
- More Samples/Explaination On Class-based architecture HOT 1
- How would you model a Weapon StateMachine having a "Idle" Movement and Cooldown in parallel? HOT 1
- Are there reasons to not use this library outside of Unity? HOT 1
- [Feature Request] States that use tasks instead of Coroutines HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unityhfsm.