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>
        /// <returns></returns>
        public bool CheckChangeState(int stateID)
        {
            if (m_States != null)
            {
                foreach (State state in m_States)
                {
                    if (state.ID == stateID)
                    {
                        m_LastState = m_CurState;
                        m_CurState  = state;
                        return(true);
                    }
                }
            }

            if (m_SubFsms != null)
            {
                foreach (SubFsm subFsm in m_SubFsms)
                {
                    if (subFsm.CheckChangeState(stateID))
                    {
                        if (subFsm != m_CurSubFsm)
                        {
                            m_LastSubFsm = m_CurSubFsm;
                            m_CurSubFsm  = subFsm;
                        }
                        return(true);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 3
0
 public Fsm()
 {
     m_Running        = false;
     m_DoDraw         = false;
     m_DoDrawSelected = false;
     m_CurState       = null;
     m_CurSubFsm      = null;
     m_States         = null;
     m_SubFsms        = null;
 }
Ejemplo n.º 4
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.º 5
0
 public SubFsm()
 {
     m_Running       = false;
     m_CurState      = null;
     m_CurSubFsm     = null;
     m_LastState     = null;
     m_LastSubFsm    = null;
     m_States        = null;
     m_SubFsms       = null;
     m_Transitions   = null;
     m_Actions       = null;
     m_SequnceAction = false;
     m_SubFsmID      = SubFsmIDGen++;
 }
Ejemplo n.º 6
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();
        }
Ejemplo n.º 7
0
        private void ExitLastState(bool onlyState = false)
        {
            if (m_LastState != null && m_LastState.Running)
            {
                m_LastState.State_Exit();
            }
            m_LastState = null;

            if (!onlyState)
            {
                if (m_LastSubFsm != null && m_LastSubFsm.Running)
                {
                    m_LastSubFsm.SubFsm_Exit();
                }
                m_LastSubFsm = null;
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 退出,内部调用
        /// </summary>
        public void SubFsm_Exit()
        {
            m_Running = false;

            if (m_CurState != null && m_CurState.Running)
            {
                m_CurState.State_Exit();
            }
            m_CurState = null;

            if (m_CurSubFsm != null && m_CurSubFsm.Running)
            {
                m_CurSubFsm.SubFsm_Exit();
            }
            m_CurSubFsm = null;

            OnExit();
        }
Ejemplo n.º 9
0
        public SubFsm AddSubFsm(SubFsm subFsm)
        {
            if (subFsm == null)
            {
                return(subFsm);
            }

            subFsm.SetSubFsm(this);

            if (m_SubFsms == null)
            {
                m_SubFsms = new List <SubFsm>()
                {
                    subFsm
                };
            }
            else if (m_SubFsms.Contains(subFsm) == false)
            {
                m_SubFsms.Add(subFsm);
            }
            return(subFsm);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// 设置SubFsm,内部调用
 /// </summary>
 /// <param name="subFsm"></param>
 public void SetSubFsm(SubFsm subFsm)
 {
     m_SubFsm = subFsm;
 }