/// <summary> /// Handles the event. /// </summary> /// <param name="eventName">Event name.</param> public void HandleEvent(ushort eventName) { if (mCurState != null && mStateDict[mCurState.Name].TranslationDict.ContainsKey(eventName)) { QFSMTranslation tempTranslation = mStateDict [mCurState.Name].TranslationDict [eventName]; tempTranslation.FromState.OnExit(); mCurState = tempTranslation.ToState; tempTranslation.ToState.OnEnter(); } }
/// <summary> /// Handles the event. /// </summary> /// <param name="eventName">Event name.</param> public void HandleEvent(ushort eventName) { if (mCurState != null && mStateDict[mCurState.Name].TranslationDict.ContainsKey(eventName)) { //状态转移,从状态字典中当前状态的转移状态从来时状态中退出 //状态转移的State换做当前状态,执行进入的OnEnter函数 var tempTranslation = mStateDict[mCurState.Name].TranslationDict[eventName]; tempTranslation.FromState.OnExit(); mCurState = tempTranslation.ToState; tempTranslation.ToState.OnEnter(); } }
public QFSMTranslation(QFSMState fromState, ushort eventName, QFSMState toState) { FromState = fromState; ToState = toState; EventName = eventName; }
/// <summary> /// Start the specified startState. /// </summary> /// <param name="startState">Start state.</param> public void Start(QFSMState startState) { mCurState = startState; mCurState.OnEnter(); }
/// <summary> /// Adds the translation. /// </summary> /// <param name="fromState">From state.</param> /// <param name="eventName">Event name.</param> /// <param name="toState">To state.</param> public void AddTranslation(QFSMState fromState, ushort eventName, QFSMState toState) { mStateDict [fromState.Name].TranslationDict.Add(eventName, new QFSMTranslation(fromState, eventName, toState)); }
/// <summary> /// Adds the state. /// </summary> /// <param name="state">State.</param> public void AddState(QFSMState state) { mStateDict.Add(state.Name, state); }
/// <summary> /// Adds the state. /// </summary> /// <param name="name">Name.</param> public void AddState(string name) { mStateDict[name] = new QFSMState(name); }
public QFSMTranslation(QFSMState fromState, ushort eventName, QFSMState toState) { this.fromState = fromState; this.toState = toState; this.eventName = eventName; }