Пример #1
0
        //通过接受过渡状态来改变当前状态
        public void PerformTransition(Transition Trans)
        {
            //该状态未空则打印错误信息并且返回
            if (Trans == Transition.NullTransition)
            {
                Debug.LogError("FSM ERROR: NullTransition is not allowed for a real transition");
                return;
            }
            //得到当前状态通过过渡状态改变后的状态
            StateID id = currentState.GetState(Trans);

            //若该状态未空则返回
            if (id == StateID.NullStateID)
            {
                Debug.LogError("FSM ERROR: State " + currentStateID.ToString() + " does not have a target state " +
                               " for transition " + Trans.ToString());
                return;
            }
            //更新当前状态
            currentStateID = id;
            foreach (FSMstate state in states)
            {
                if (state.ID == currentStateID)
                {
                    currentState.DoBeforeLeaving(ai, po);
                    currentState = state;
                    currentState.DoBeforeEntering();
                    break;
                }
            }
        }