Exemple #1
0
        public void Start(Type stateType)
        {
            if (IsRunning)
            {
                throw new GameFrameworkException("FSM is running, can not start again.");
            }

            if (stateType == null)
            {
                throw new GameFrameworkException("State type is invalid.");
            }

            if (!typeof(AFsmState<T>).IsAssignableFrom(stateType))
            {
                throw new GameFrameworkException(string.Format("State type '{0}' is invalid.", stateType.FullName));
            }

            AFsmState<T> state = GetState(stateType);
            if (state == null)
            {
                throw new GameFrameworkException(string.Format("FSM '{0}' can not start state '{1}' which is not exist.", state, stateType.FullName));
            }

            m_CurrentStateTime = 0f;
            m_CurrentState = state;
            m_CurrentState.OnEnter(this);
        }
Exemple #2
0
        /// <summary>
        /// 开始有限状态机。
        /// </summary>
        /// <typeparam name="TState">要开始的有限状态机状态类型。</typeparam>
        public void Start<TState>() where TState : AFsmState<T>
        {
            if (IsRunning)
            {
                throw new GameFrameworkException("FSM is running, can not start again.");
            }

            AFsmState<T> state = GetState<TState>();
            if (state == null)
            {
                throw new GameFrameworkException(string.Format($"FSM can not start state {typeof(TState).FullName} which is not exist."));
            }

            m_CurrentStateTime = 0f;
            m_CurrentState = state;
            m_CurrentState.OnEnter(this);
        }
Exemple #3
0
        public void ChangeState(Type stateType)
        {
            if (m_CurrentState == null)
            {
                throw new GameFrameworkException("Current state is invalid.");
            }

            AFsmState<T> state = GetState(stateType);
            if (state == null)
            {
                throw new GameFrameworkException(string.Format("FSM '{0}' can not change state to '{1}' which is not exist.", state, stateType.FullName));
            }

            m_CurrentState.OnLeave(this);
            m_CurrentStateTime = 0f;
            m_CurrentState = state;
            m_CurrentState.OnEnter(this);
        }