public void ChangePrevState() { if (savePrevState != null && curState.ID == savePrevState.ID) { return; } if (curState != null) { curState.Leave(); } curState = savePrevState; curState.Enter(); prevState = curState; }
public BaseGameState savePrevState; //上一个状态 public void ChangeState(BaseGameState newState) { if (curState != null && curState.ID == newState.ID) { return; } if (prevState != null) { savePrevState = prevState; prevState.Leave(); } curState = newState; curState.Enter(); prevState = curState; }
void ChangeState(Type type) { if (_nowState == null) { _nowState = GetState(type); _nowState.Enter(null); _willStateType = null; return; } if (_nowState.GetType() == type) { return; } if (_willStateType != null && _willStateType == type) { return; } _willStateType = type; _nowState.Leave(); }