public void RemoveState(txStateID state_id, txStateID new_state_if_current) { XUtils.Assert(!mLocked, "Modifying state machine while in use not allowed."); // if that was the current state, prepare to switch states as indicated. // remove all transitions to that state from other states. // remove state. XState next_state = null; if (mCurrentState.mStateID.Equals(state_id)) { XUtils.Assert(!new_state_if_current.Equals(state_id)); if (new_state_if_current.Equals(txStateID.kNone)) { XUtils.Assert(mStates.Count == 1, "can only switch to no current state if removing the last state"); mCurrentState = null; } else { bool found_next = mStates.TryGetValue(new_state_if_current, out next_state); XUtils.Assert(found_next); } } for (int i = 0; i < mStates.Count; ++i) { var state_i = mStates.ElementAt(i); state_i.Value.RemoveTransitionsTo(state_id); } if (next_state != null) { mCurrentState = next_state; } XState state; bool found = mStates.TryGetValue(state_id, out state); XUtils.Assert(found); mStates.Remove(state_id); }
public void SetStartingState(txStateID starting_state) { XUtils.Assert(mCurrentState == null); XUtils.Assert(!starting_state.Equals(txStateID.kNone)); mCurrentState = GetState(starting_state); }