/// <summary> /// 设置FSM进入状态,状态机开始运行 /// </summary> /// <param name="uEntranceStateId"></param> public virtual bool Start() { m_AnyState = GetState(m_uAnyStateId); bool bRet = ChangeToState(m_uEnteranceStateId, null); return(bRet); }
/// <summary> /// 设置FSM进入状态,状态机开始运行 /// </summary> public virtual bool Start() { if (m_CurrentState != null) { return(false); } m_AnyState = GetState(m_uAnyStateId); bool bRet = ChangeToState(m_uEnteranceStateId, null); return(bRet); }
/// <summary> /// 设置FSM进入状态,状态机开始运行 /// </summary> /// <param name="uEntranceStateId"></param> public bool Start(UInt32 uEntranceStateId) { if (m_CurrentState != null) { return(false); } m_uEnteranceStateId = uEntranceStateId; m_AnyState = GetState(m_uAnyStateId); bool bRet = ChangeToState(m_uEnteranceStateId, null); return(bRet); }
/// <summary> /// 获取一个状态 /// </summary> /// <param name="uStateId"></param> /// <returns></returns> protected CFSMState GetState(UInt32 uStateId) { Int32 nSize = m_StateList == null ? 0 : m_StateList.Count; for (Int32 i = 0; i < nSize; ++i) { CFSMState state = m_StateList[i]; if (state != null && state.GetStateID() == uStateId) { return(state); } } return(null); }
/// <summary> /// 添加一个状态 /// </summary> /// <param name="newState"></param> /// <returns></returns> public bool AddState(CFSMState newState) { if (newState == null) { return(false); } if (GetState(newState.GetStateID()) != null) // dup { return(false); } if (m_StateList == null) { m_StateList = new List <CFSMState>(); } m_StateList.Add(newState); return(true); }
/// <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); }
/// <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); }