예제 #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();
                }
            }
        }
예제 #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);
        }
예제 #3
0
파일: Fsm.cs 프로젝트: laijingfeng/JerryFsm
 public Fsm()
 {
     m_Running        = false;
     m_DoDraw         = false;
     m_DoDrawSelected = false;
     m_CurState       = null;
     m_CurSubFsm      = null;
     m_States         = null;
     m_SubFsms        = null;
 }
예제 #4
0
파일: Fsm.cs 프로젝트: laijingfeng/JerryFsm
        /// <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;
                    }
                }
            }
        }
예제 #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++;
 }
예제 #6
0
파일: Fsm.cs 프로젝트: laijingfeng/JerryFsm
        /// <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();
        }
예제 #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;
            }
        }
예제 #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();
        }
예제 #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);
        }
예제 #10
0
 /// <summary>
 /// 设置SubFsm,内部调用
 /// </summary>
 /// <param name="subFsm"></param>
 public void SetSubFsm(SubFsm subFsm)
 {
     m_SubFsm = subFsm;
 }