Esempio n. 1
0
        /// <summary>
        /// 切换到一个状态
        /// </summary>
        /// <param name="uNextState"></param>
        /// <param name="fsmEvent"></param>
        /// <returns></returns>
        public bool ChangeToState(UInt32 uNextState, CFSMEvent fsmEvent)
        {
            CFSMState nextFSMState = GetState(uNextState);

            if (nextFSMState == null)
            {
                BTDebug.Warning(string.Format("Found NO State With ID:{0}, Change State Failed", uNextState), "FSM");
                return(false);
            }

            if (m_CurrentState != null)
            {
                if (m_CurrentState.GetStateID() == uNextState)
                {
                    return(true);
                }

                if (m_CurrentState.OnExit(this, fsmEvent) == false)
                {
                    BTDebug.Warning(string.Format("State:{0} Exit Failed", m_CurrentState.GetStateName()), "FSM");
                }
            }

#if BTDEBUG
            if (m_bOpenDebug)
            {
                string strLog = string.Format("FSM Trans From:{0} To:{1}",
                                              m_CurrentState == null ? "NULL" : m_CurrentState.GetStateName(),
                                              nextFSMState.GetStateName());

                BTDebug.Log(strLog, "BTFSM");
            }
#endif

            m_CurrentState = nextFSMState;

            if (nextFSMState.OnEnter(this, fsmEvent) == false)
            {
                BTDebug.Warning(string.Format("State:{0} Enter Failed", nextFSMState.GetStateName()), "FSM");
            }

            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// 切换到一个状态
        /// </summary>
        /// <param name="uNextState"></param>
        /// <param name="fsmEvent"></param>
        /// <returns></returns>
        public bool ChangeToState(UInt32 uNextState, CFSMEvent fsmEvent)
        {
            CFSMState nextFSMState = GetState(uNextState);

            if (nextFSMState == null)
            {
                return(false);
            }

            if (m_CurrentState != null)
            {
                if (m_CurrentState.GetStateID() == uNextState)
                {
                    return(true);
                }

                if (m_CurrentState.OnExit(this, fsmEvent) == false)
                {
                    BTDebug.Warning(string.Format("<BTFSM> State:{0} Exit Failed", m_CurrentState.GetStateName()));
                }
            }

#if BTDEBUG
            if (m_bOpenDebug)
            {
                BTDebug.Log(string.Format("<BTFSM> FSM Trans From:{0} To:{1}",
                                          m_CurrentState == null ? "NULL" : m_CurrentState.GetStateName(),
                                          nextFSMState.GetStateName()));
            }
#endif

            if (nextFSMState.OnEnter(this, fsmEvent) == false)
            {
                BTDebug.Warning(string.Format("<BTFSM> State:{0} Enter Failed", nextFSMState.GetStateName()));
            }

            m_CurrentState = nextFSMState;

            return(true);
        }