Exemplo n.º 1
0
        /// <summary>
        /// 切换状态
        /// </summary>
        /// <param name="type">状态类型</param>
        public void SwitchState(Type type)
        {
            if (_stateDic.ContainsKey(type))
            {
                if (_currState == _stateDic[type])
                {
                    return;
                }

                BaseFSMState lastState = _currState;
                BaseFSMState nextState = _stateDic[type];
                if (lastState != null)
                {
                    lastState.OnLeave(nextState);
                }
                nextState.OnEnter(lastState);
                _currState = nextState;
            }
            else
            {
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 启动默认状态
 /// </summary>
 public void StartFirst()
 {
     _currState = _firstState;
     _currState.OnEnter(null);
 }