public void AddState(IBearState state) { if (state == null) { Debug.LogError("要添加的状态为空"); return; } if (mStates.Count == 0) { mStates.Add(state); mCurrentState = state; currentState.DoBeforeEntering(); return; } foreach (IBearState s in mStates) { if (s.stateID == state.stateID) { Debug.LogError("要添加的状态ID[" + s.stateID + "]已经添加"); return; } } mStates.Add(state); }
public void ChangeState(IBearState newState) { if (_currentState != null) { _currentState.Exit(); } _currentState = newState; _currentState.Enter(this); }
public void PerformTransition(BearTransition trans) { if (trans == BearTransition.NullTransition) { Debug.LogError("要执行的转换条件为空:" + trans); return; } BearStateID nextStateID = mCurrentState.GetOutPutState(trans); if (nextStateID == BearStateID.NullState) { Debug.LogError("在转换条件[" + trans + "]下,没有对应的转换状态"); return; } foreach (IBearState s in mStates) { if (s.stateID == nextStateID) { mCurrentState.DoBeforeLeaving(); mCurrentState = s; mCurrentState.DoBeforeEntering(); return; } } }