Ejemplo n.º 1
0
        /// <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();
                }
            }
        }
Ejemplo n.º 2
0
        /// <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;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 内部调用
        /// </summary>
        public void Fsm_Start()
        {
            if (m_States != null && m_States.Count > 0)
            {
                m_CurState = m_States[0];
                m_CurState.State_Enter();
            }
            else if (m_SubFsms != null && m_SubFsms.Count > 0)
            {
                m_CurSubFsm = m_SubFsms[0];
                m_CurSubFsm.SubFsm_Enter();
            }

            m_Running = true;
            OnStart();
        }