protected override void OnStart() { base.OnStart(); m_FSM = new StateMachine(this); m_FSM.AddState(new FindEnemyState()); m_FSM.AddState(new BackToHomeState()); m_FSM.AddState(new FindStarState()); m_FSM.SetDefaultState((int)EStateType.FindStar); }
public MainWindow() { InitializeComponent(); sm.AddState(new HappyState()); sm.AddState(new SadState()); sm.AddState(new ArousalState()); sm.AddState(new BoredomState()); statesDropDown.ItemsSource = sm.States; StateStatusController.Instance.OnStatusChange += UpdateStateStatus; }
/* * "Shortcut" methods * - These are meant to reduce the boilerplate code required by the user for simple * states and transitions. * - They do this by creating a new State / Transition instance in the background * and then setting the desired fields. * - They can also optimise certain cases for you by choosing the best type, * such as a StateBase for an empty state instead of a State instance. */ /// <summary> /// Shortcut method for adding a regular state. /// It creates a new State() instance under the hood. => See State for more information. /// For empty states with no logic it creates a new StateBase for optimal performance. /// </summary> public static void AddState <TOwnId, TStateId, TEvent>( this StateMachine <TOwnId, TStateId, TEvent> fsm, TStateId name, Action <State <TStateId, TEvent> > onEnter = null, Action <State <TStateId, TEvent> > onLogic = null, Action <State <TStateId, TEvent> > onExit = null, Func <State <TStateId, TEvent>, bool> canExit = null, bool needsExitTime = false) { // Optimise for empty states if (onEnter == null && onLogic == null && onExit == null && canExit == null) { fsm.AddState(name, new StateBase <TStateId>(needsExitTime)); return; } fsm.AddState(name, new State <TStateId, TEvent>(onEnter, onLogic, onExit, canExit, needsExitTime)); }