/// <summary> /// Registers a new state /// </summary> /// <param name="state">State to register</param> public void RegisterState(JState state) { statesList.Add(state); //We set a reference to this machine to the state so it will be able //to change the current state from within any state state.SetStateMachine(this); }
/// <summary> /// Changes the current state with a registered state /// </summary> /// <param name="state">Name of the state</param> public bool SetCurrentState(string state) { //Run exiting code for the current state if (currentState != null) currentState.OnExit(); //Set the new current state currentState = statesList.FindFirst(state); //Run the entering code for the new current state if (currentState != null) return currentState.OnEnter(); return false; }
/// <summary> /// Changes the current state with a registered state /// </summary> /// <param name="state">Name of the state</param> public bool SetCurrentState(string state) { //Run exiting code for the current state if (currentState != null) { currentState.OnExit(); } //Set the new current state currentState = statesList.FindFirst(state); //Run the entering code for the new current state if (currentState != null) { return(currentState.OnEnter()); } return(false); }
/// <summary> /// Default constructor /// </summary> public JStateMachine() { currentState = null; statesList = new JList <JState>(); }
/// <summary> /// Default constructor /// </summary> public JStateMachine() { currentState = null; statesList = new JList<JState>(); }