//执行状态转换
    public void PerformTransition(SoldierTransition trans)
    {
        if (trans == SoldierTransition.NullTransition)
        {
            Debug.LogError("转换条件不能为空");
            return;
        }

        SoldierStateID nextId = currentState.GetOutputState(trans);

        if (nextId == SoldierStateID.NullStateID)
        {
            Debug.LogError("转换的状态不能为空");
            return;
        }

        foreach (SoldierState state in states)
        {
            if (state.ID != nextId)
            {
                continue;
            }

            currentState.DoBeforeLeaving();  //转换前执行现有状态的DoBeforeLeaving方法
            currentState = state;
            currentState.DoBeforeEntering(); //转换完成,执行转换后状态的DoBeforeEntering方法
            return;
        }
    }
예제 #2
0
    public void PerformTransition(SoldierTransition tran)
    {
        if (tran == SoldierTransition.NullTransition)
        {
            Debug.Log("要执行的转换条件为空");
        }

        SoldierStateType nextState = mCurrentState.GetTargetStateType(tran);

        if (nextState == SoldierStateType.NullState)
        {
            Debug.Log("在 " + tran + " 条件下,没有对应的目标状态");
            return;
        }

        foreach (SoldierState item in mStates)
        {
            if (item.StateType == nextState)
            {
                mCurrentState.DoBeforeLeaving();
                mCurrentState = item;
                mCurrentState.DoBeforeEntering();
            }
        }
    }