/// <summary> /// FSM事件 /// </summary> /// <param name="uEventID"></param> public void OnFSMEvent(UInt32 uEventID) { CFSMEvent newFSMEvent = new CFSMEvent(); newFSMEvent.SetEventId(uEventID); OnFSMEvent(newFSMEvent); }
/// <summary> /// 状态更新 /// </summary> /// <param name="fsmEntity"></param> /// <param name="fsmEvent"></param> public override bool Process(CFSM fsmEntity, CFSMEvent fsmEvent) { if (m_ProcessActionList == null) { return(true); } if (fsmEntity == null) { return(false); } Int32 nActionSize = m_ProcessActionList.Count; bool bInvokeRet = true; for (Int32 i = 0; i < nActionSize; ++i) { CFSMAction action = m_ProcessActionList[i]; if (action == null) { continue; } System.Object objReturnValue = null; bInvokeRet &= action.InvokeWhenPipelineOpen(fsmEntity, out objReturnValue); } return(bInvokeRet); }
/// <summary> /// 转换通道是否畅通 /// 重载 /// </summary> /// <param name="fsmEntity"></param> /// <returns></returns> public override bool IsPipelineOpen(CFSM fsmEntity) { if (m_EventTrigger == null) { return(false); } List <CFSMEvent> listenedEventList = fsmEntity.GetListenedEvent(); if (listenedEventList == null) { return(false); } Int32 nSize = listenedEventList == null ? 0 : listenedEventList.Count; for (Int32 i = 0; i < nSize; ++i) { CFSMEvent listenedEvent = listenedEventList[i]; bool bTrigger = m_EventTrigger.Trigger(listenedEvent); if (bTrigger == true) { return(true); } } return(false); }
/// <summary> /// 触发状态机事件 /// </summary> /// <param name="fsmEvent"></param> /// <returns></returns> public bool Trigger(CFSMEvent fsmEvent) { if (fsmEvent == null) { return(false); } if (fsmEvent.GetEventId() != m_uTriggerEventId) { return(false); } return(true); }
/// <summary> /// FSM事件 /// </summary> /// <param name="fsmEvent"></param> public virtual void OnFSMEvent(CFSMEvent fsmEvent) { #if BTDEBUG if (m_bOpenDebug == true && fsmEvent != null) { BTDebug.Log(string.Format("<BTFSM> FSM Receive Event:{0}", fsmEvent.GetEventId())); } #endif if (m_ListenedEventList == null) { return; } m_ListenedEventList.Add(fsmEvent); }
/// <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); }
/// <summary> /// 进入状态 /// </summary> /// <param name="fsmEntity"></param> /// <param name="fsmEvent"></param> public abstract bool OnEnter(CFSM fsmEntity, CFSMEvent fsmEvent);
/// <summary> /// 状态更新 /// </summary> /// <param name="fsmEntity"></param> /// <param name="fsmEvent"></param> public abstract bool Process(CFSM fsmEntity, CFSMEvent fsmEvent);