Example #1
0
 public virtual void SwitchState(T stateType)
 {
     if (currentState != null && currentState.GetStateType().Equals(stateType))
     {
         return;
     }
     if (currentState != null)
     {
         currentState.Leave();
     }
     currentState = allStates[stateType];
     currentState.Enter();
 }
Example #2
0
    public void PerformTransition(Transition trans)
    {
        if (trans == Transition.NullTransition)
        {
            Debug.LogError("无法执行空的转换条件");
        }
        StateName stateName = currentFsmState.GetStateName(trans);

        if (stateName == StateName.NullStateName)
        {
            Debug.LogError("当前状态" + stateName + "无法根据条件" + trans + "发生转换");
            return;
        }
        if (stateDic.ContainsKey(stateName) == false)
        {
            Debug.LogError("在状态机里面不存在该状态" + stateName + ",无法进行状态转换!");
            return;
        }
        currentFsmState.Exit();
        currentFsmState  = stateDic[stateName];
        currentStateName = currentFsmState.stateName;
        currentFsmState.Enter();
    }