public void ChangeState(IStateMachine newState) { if (currentState != null) { currentState.Exit(); //exit the old state & run whatever functionality is in the old state's exit } // enter the new state currentState = newState; currentState.Enter(); }
public StateManager(IStateMachine initialState) { if ((initialState == null)) { throw new Exception("initialState cannot be null"); } IemUtils.SLog(this.GetType().Name + ":CREATING"); //set the initial state currentState = initialState; //@todo not sure if this is correct. should we enter the initial state? currentState.Enter(this); IemUtils.SLog(this.GetType().Name + ":initialstate:" + currentState.ToString().Replace("Oxide.Plugins.", "")); }
/// <summary> /// enter a substate, where you want to revert to the previous state /// </summary> /// <param name="newState"></param> public virtual void SubState(IStateMachine newState) { if ((currentState == null)) { throw new Exception("currentState state is null"); } if ((newState == null)) { throw new Exception("newState is null"); } IemUtils.SLog(this.GetType().Name + ":ChangeState:PrevState:" + currentState); previousState = currentState; currentState = newState; currentState.Enter(this); IemUtils.SLog(this.GetType().Name + ":ChangeState:newstate:" + newState); }
public virtual void ChangeState(IStateMachine newState) { //@todo probably want to throw exception instead if ((currentState == null) || (newState == null)) { throw new Exception("can't change from or to invalid state"); } //IemUtils.SLog("stateManager:"+ this.GetType().Name); IemUtils.SLog(this.GetType().Name + ":ChangeState:oldstate:" + currentState.ToString().Replace("Oxide.Plugins.", "")); currentState.Exit(this); previousState = currentState; currentState = newState; currentState.Enter(this); IemUtils.SLog(this.GetType().Name + ":ChangeState:newstate:" + newState.ToString().Replace("Oxide.Plugins.", "")); }