Beispiel #1
0
        /// <summary>
        /// 切换状态
        /// </summary>
        /// <param name="type">状态类型</param>
        public void SwitchState(Type type)
        {
            if (_stateInstances.ContainsKey(type))
            {
                if (_currentState == _stateInstances[type])
                {
                    return;
                }

                FiniteStateBase lastState = _currentState;
                FiniteStateBase nextState = _stateInstances[type];
                if (lastState != null)
                {
                    lastState.OnLeave(nextState);
                }
                nextState.OnEnter(lastState);
                _currentState = nextState;

                AnyStateSwitchEvent?.Invoke(lastState, nextState);
            }
            else
            {
                throw new HTFrameworkException(HTFrameworkModule.FSM, "切换状态失败:有限状态机 " + Name + " 不存在状态 " + type.Name + "!");
            }
        }
Beispiel #2
0
        /// <summary>
        /// 切换状态
        /// </summary>
        /// <param name="type">状态类型</param>
        public void SwitchState(Type type)
        {
            if (_stateInstances.ContainsKey(type))
            {
                if (CurrentState == _stateInstances[type])
                {
                    return;
                }

                FiniteStateBase lastState = CurrentState;
                FiniteStateBase nextState = _stateInstances[type];
                if (lastState != null)
                {
                    lastState.OnLeave(nextState);
                }
                nextState.OnEnter(lastState);
                CurrentState = nextState;

                AnyStateSwitchEvent?.Invoke(lastState, nextState);
            }
            else
            {
                Log.Warning("切换状态失败:有限状态机 " + Name + " 不存在状态 " + type.Name + "!");
            }
        }