Пример #1
0
    /// <summary>
    /// 执行过渡条件
    /// </summary>
    /// <param name="_transition">Transition.</param>
    public void PerformTransition(Transition _transition)
    {
        if (_transition == Transition.None)
        {
            Debug.LogError("PerformTransition _transition error : transition is none");
            return;
        }
        FSMState stateBase = currentState.GetOutPutState(_transition);

        if (stateBase == FSMState.None)
        {
            Debug.LogError("PerformTransition _transition error : State does not have a target state  for transition");
            return;
        }
        for (int i = 0; i < statesList.Count; i++)
        {
            if (statesList[i].FSMState == stateBase)
            {
                currentState.DoBeforeLeaving();
                //只有这样切换才给上一个状态赋值,当前状态已经变成了上一个状态
                BeforeState = currentState;
                //当前状态已经被转换
                currentState = statesList[i];
                currentState.DoBeforeEntering();
            }
        }
    }
Пример #2
0
 /// <summary>
 /// 执行状态基类
 /// </summary>
 /// <param name="_stateBase">State base.</param>
 public void PerformTransition(FSMStateBase _stateBase)
 {
     Debug.Log(currentState.ToString() + " -> " + _stateBase.ToString());
     currentState.DoBeforeLeaving();
     currentState = _stateBase;
     currentState.DoBeforeEntering();
 }