Beispiel #1
0
    /// <summary>
    /// 通过转换,改变FSM的状态
    /// </summary>
    public void PerformTransition(Transition trans)
    {
        if (trans == Transition.NullTransition)
        {
            Debug.LogError("FSM ERROR: NullTransition is not allowed for a real transition");
            return;
        }
        //获取转换对应的状态ID
        StateID id = CurrentState.GetOutputState(trans);

        if (id == StateID.NullStateID)
        {
            Debug.LogError("FSM ERROR: State " + CurrentStateID.ToString() + " does not have a target state " +
                           " for transition " + trans.ToString());
            return;
        }

        // 更新当前状态ID,currentStateID
        CurrentStateID = id;
        foreach (FSMState state in m_States)
        {
            if (state.ID == CurrentStateID)
            {
                // 离开状态时的变量重置
                CurrentState.DoBeforeLeaving();
                // 更新当前状态currentState
                CurrentState = state;
                // 进入状态前,设置进入的状态条件
                CurrentState.DoBeforeEntering();
                break;
            }
        }
    }
Beispiel #2
0
    /// <summary>
    /// 状态改变
    /// </summary>
    public void SwitchTransition(Transition trans)
    {
        //在改变当前状态前检测NullTransition
        if (trans == Transition.NullTransition)
        {
            Debug.LogError("FSM ERROR: NullTransition is not allowed for a real transition");
            return;
        }

        //在改变当前状态前检测当前状态是否可作为过渡的参数
        StateID id = CurrentState.GetOutputState(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;
        for (int i = 0; i < states.Count; i++)
        {
            if (states[i].ID == CurrentStateID)
            {
                //离开旧状态执行方法
                CurrentState.OnExit();
                CurrentState = states[i];
                //进入新的状态
                CurrentState.OnEnter();
                break;
            }
        }
    }
Beispiel #3
0
 public override void UpdateController()
 {
     if (this.Fsm != null && this.Fsm.CurrentState != null)
     {
         if (LastStateID != CurrentStateID)
         {
             Debug.Log("유닛 상태 변화 : " + LastStateID.ToString() + " 에서 " + CurrentStateID.ToString());
             LastStateID = CurrentStateID;
         }
         this.Fsm.CurrentState.DoCheck();
         this.Fsm.CurrentState.DoAct();
     }
     if (this.aniController != null)
     {
         this.aniController.UpdateAnimation();
     }
     //Tip Y축 위치에따라 소팅.
     //this.aniController.sprite_main.SortingOrder = 10000 - (int)this.myTransform.position.y;
 }
        /// <summary>
        /// This method tries to change the state the FSM is in based on
        /// the current state and the transition passed. If current state
        ///  doesn't have a target state for the transition passed,
        /// an ERROR message is printed.
        /// </summary>
        public void PerformTransition(Transition trans, bool ifGlobal)
        {
            // Check for NullTransition before changing the current state
            if (trans == Transition.NullTransition)
            {
                return;
            }

            // Check if the currentState has the transition passed as argument
            StateID id;

            if (!ifGlobal)
            {
                id = CurrentState.GetOutputState(trans);
            }
            else
            {
                id = GlobalState.GetOutputState(trans);
            }
            if (id == StateID.NullStateID)
            {
                Debug.LogError("FSM ERROR: State " + CurrentStateID.ToString() + " does not have a target state " +
                               " for transition " + trans.ToString());
                return;
            }

            // Update the currentStateID and currentState
            CurrentStateID = id;
            foreach (FSMState <T> state in states)
            {
                if (state.ID == CurrentStateID)
                {
                    // Do the post processing of the state before setting the new one
                    CurrentState.DoBeforeLeaving();

                    CurrentState = state;

                    // Reset the state to its desired condition before it can reason or act
                    CurrentState.DoBeforeEntering();
                    break;
                }
            }
        } // PerformTransition()