/// <summary> /// 添加一个状态 /// </summary> /// <param name="state"></param> public void AddState(FSMBaseState state) { if (!allStateDic.ContainsKey(state.stateName)) { allStateDic.Add(state.stateName, state); } }
/// <summary> /// 构造方法 /// </summary> public FSMManager(object control) { this.control = control; FSMBaseState rootState = new FSMBaseState(FSMBaseState.RootState, this); AddState(rootState); TranslateToState(FSMBaseState.RootState); }
/// <summary> /// 转移到某个状态 /// </summary> /// <param name="stateName"></param> public void TranslateToState(string stateName) { if (CurrentState != null) { if (stateName != CurrentState.stateName) { CurrentState.OnStateInvoke(StateEnum.StateExit); CurrentState = this[stateName]; CurrentState.OnStateInvoke(StateEnum.StateEnter); } } else { CurrentState = this[stateName]; CurrentState.OnStateInvoke(StateEnum.StateEnter); } }