Skip to content

A lightweight implementation for a stacked state machine in C#.

License

Notifications You must be signed in to change notification settings

homoroselaps/StackedStateMachine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

StackedStateMachine

A lightweight implementation for a stacked state machine in C#. It's designed to control any actions of an NPC in a game. Part of the project is a sample console application simulating the actions of a carrier with verbose output.

Usage

Create a new instance:

var ssm = new StackedStateMachine(<inital State>);

Configure transitions:

ssm.addTransition(<typeof active State>, <typeof Event>, <delegate that returns the new state>);

Execute active state's action and control the state machine with external events:

var e = ssm.State.onGameTick();
if (e != null) ssm.raiseEvent(e);

Default Events

AbortEvent:

The active state raises it, if it runs into problems. Raise it externally to abort the active action and to initiate rollback of the state stack.

DoneEvent:

The active state raises it, if the action is done. Hands over control to the previous state on the state stack.

About

A lightweight implementation for a stacked state machine in C#.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages