/// <summary> /// 状态切换,内部调用 /// </summary> public void DoChangeState() { if (m_CurState != null) { if (m_CurState == m_LastState) { ExitLastState(); m_CurState.m_ReadyToEnter = true; } else { ExitLastState(); m_CurState.State_Enter(); } return; } if (m_CurSubFsm != null) { ExitLastState(true); if (m_CurSubFsm != m_LastSubFsm) { if (m_LastSubFsm != null && m_LastSubFsm.Running) { m_LastSubFsm.SubFsm_Exit(); } m_LastSubFsm = null; m_CurSubFsm.SubFsm_Enter(); } else { m_CurSubFsm.DoChangeState(); } } }
/// <summary> /// 可供外部调用,用来强制跳转 /// </summary> /// <param name="stateID"></param> public void ChangeState(int stateID) { if (m_States != null) { foreach (State state in m_States) { if (state.ID == stateID) { if (m_CurState == state) { ExitLastState(); m_CurState = state; m_CurState.m_ReadyToEnter = true; } else { ExitLastState(); m_CurState = state; m_CurState.State_Enter(); } return; } } } if (m_SubFsms != null) { foreach (SubFsm subFsm in m_SubFsms) { if (subFsm.CheckChangeState(stateID)) { ExitLastState(true); if (subFsm != m_CurSubFsm) { if (m_CurSubFsm != null && m_CurSubFsm.Running) { m_CurSubFsm.SubFsm_Exit(); } m_CurSubFsm = subFsm; m_CurSubFsm.SubFsm_Enter(); } else { m_CurSubFsm.DoChangeState(); } return; } } } }