State - SimpleStateMachine/SimpleStateMachineLibrary GitHub Wiki

Сontent

Create

//Throw exeption if state already exist
State state1 = stateMachine.AddState("State1");

//Return null if state already exist
State state1 = stateMachine.TryAddState(out bool result, "State1");

Get

//Throw exeption if state not found
State state1 = stateMachine.GetState("State1");

//Return null if state not found
State state1 = stateMachine.TryGetState("State1", out bool result);

Exists

//You can check on exists
bool state1IsExists = stateMachine.StateExists("State1");

Delete

Delete with name


//Throw exeption if state not found
stateMachine.DeleteState("State1");

stateMachine.TryDeleteState("State1");

Delete with object


//Throw exeption if state not found
stateMachine.DeleteState(state1);

stateMachine.TryDeleteState(state1);

//Throw exeption if state already delete from state machine
state1.Delete();

state1.TryDelete(out bool result);

Entry

Triggered after invoke transition. You can set many action for one state, but transition will be invoke that was called last

Action Syntax

Read about action parameters

void ActionOnEtnry(State state, Dictionary<string, object> parameters)
{
 //you need invoke transition in entry or exit action, differently work state machine will be end
 state.StateMachine.InvokeTransition("Transition1");
}

Add action

//you can set action with add
State state1 = stateMachine.AddState("State1", actionOnEntry: ActionOnEtnry);

//you can set action after add
State state1 = stateMachine.AddState("State1").OnEntry(ActionOnEtnry);

state1.OnEntry(ActionOnEtnry); 
  

Exit

Triggered after entry to state. You can set many action for one state, but transition will be invoke that was called last

Action Syntax

Read about action parameters

void ActionOnExit(State state, Dictionary<string, object> parameters)
{
 //you need invoke transition in entry or exit action, differently work state machine will be end
 state.StateMachine.InvokeTransition("Transition1");
}

Add action

//you can set action with add
State state1 = stateMachine.AddState("State1", actionOnExit: ActionOnExit);

//you can set action after add
State state1 = stateMachine.AddState("State1").OnExit(ActionOnExit);

state1.OnExit(ActionOnExit);  

You can say actions on entry and exit together with add


State state1 = stateMachine.AddState("State1",actionOnEntry: ActionOnEtnry, actionOnExit: ActionOnExit);