DoBeforeLeaving() public method

public DoBeforeLeaving ( ) : void
return void
Exemplo n.º 1
0
	// for AI controled FSM transfer
	public void PerformAITransition(StateID NextStateID)
	{
		currentStateID = NextStateID;
		foreach (FSMState state in states)
		{
			if (state.ID == currentStateID)
			{
				currentState.DoBeforeLeaving();
				currentState = state;
				currentState.DoBeforeEntering();
				break;
			}
		}
	}
Exemplo n.º 2
0
    public void PerformTransition(FSMTransition trans)
    {
        if (trans == FSMTransition.NullTransition)
        {
            return;
        }

        FSMStateId id = currentState.GetOutputStateId(trans);

        if (id == FSMStateId.NullState)
        {
            return;
        }

        currentStateId = id;
        foreach (FSMState state in stateList)
        {
            if (state.StateID == id)
            {
                currentState.DoBeforeLeaving();

                currentState = state;

                currentState.DoBeforeEntering();

                break;
            }
        }
    }
    //执行状态转换
    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.GetOutputState(trans);

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

        currentStateID = id;
        foreach (FSMState state in states)
        {
            if (state.ID != currentStateID)
            {
                continue;
            }

            currentState.DoBeforeLeaving();//转换前执行现有状态的DoBeforeLeaving方法

            currentState = state;

            currentState.DoBeforeEntering();//转换完成,执行转换后状态的DoBeforeEntering方法
            break;
        }
    }
Exemplo n.º 4
0
 /// <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 DoTransition(FSMState targetState)
 {
     _currentState.DoBeforeLeaving();
     _currentState = targetState;
     _owner.UpdateStateView(_currentState);
     _currentState.DoBeforeEntering();
 }
Exemplo n.º 5
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.GetOutputState(trans);

        if (id == StateID.NullState)
        {
            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();

                currentState = state;

                currentState.DoBeforeEntering();
                break;
            }
        }
    }
Exemplo n.º 6
0
    /// <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)
    {
        // Check for NullTransition before changing the current state
        if (trans == Transition.NullTransition)
        {
            Debug.LogError("FSM ERROR: NullTransition is not allowed for a real transition");
            return;
        }

        // Check if the currentState has the transition passed as argument
        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;
        }

        // Update the currentStateID and currentState
        currentStateID = id;
        foreach (FSMState 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;
            }
        }
    }
Exemplo n.º 7
0
    public void PerformTransition(Transition trans)
    {
        string errorMsg = "";

        if (trans == Transition.NullTransition)
        {
            errorMsg = "NullTransition is not allowed for a real transition.";
            FSMSystemError(errorMsg);
            return;
        }

        StateID id = currentState.GetOutputState(trans);

        if (id == StateID.NullStateID)
        {
            errorMsg = "State " + currentStateID.ToString() + " does not have a target state for transition " + trans.ToString();
            FSMSystemError(errorMsg);
            return;
        }

        currentStateID = id;
        foreach (FSMState state in states)
        {
            if (state.ID == currentStateID)
            {
                currentState.DoBeforeLeaving();
                currentState = state;
                currentState.DoBeforeEntering();
                break;
            }
        }
    }
Exemplo n.º 8
0
    public void PerformTransition(Transition trans)
    {
        if (trans == Transition.NullTransition)
        {
            //  Debug.LogError("trans is NullTransition");
            return;
        }

        StateID id = currentState.GetOutputState(trans);

        if (id == StateID.NullStateID)
        {
            //  Debug.LogError("id is nullStateID");
            return;
        }

        currentStateID = id;
        foreach (FSMState state in states)
        {
            if (state.ID == currentStateID)
            {
                currentState.DoBeforeLeaving();

                currentState = state;

                currentState.DoBeforeEntering();
                break;
            }
        }
    }
Exemplo n.º 9
0
    /// <summary>
    /// 该方法基于当前的状态和transition来尝试去改变FSM的状态,如果当前状态没有一个可以通过transition到达的状态,就会报错
    /// </summary>
    /// <param name="trans"></param>
    public void PerformTransition(Transition trans)
    {
        //检验空状态
        if (trans == Transition.NullTransition)
        {
            //打印错误信息
            Debug.LogError($"FSM ERROR NUllTransition is not allowed for a real transition");
            return;
        }

        //检查当前状态能不能通过transition到达其他状态
        StateID id = currentState.GetOutputStateID(trans);

        if (id == StateID.NullStateId)
        {//表示在currentState的dic中没有trans可以去
            Debug.Log($"FSM ERROR State {currentStateID.ToString()} does not have a target state for transition {trans.ToString()}");
            return;
        }

        //更新currentState和currentStateId
        currentStateID = id;
        foreach (var state in states)
        {
            if (state.ID == currentStateID)      //如果在states中找到了我们要转向的状态
            {
                currentState.DoBeforeLeaving();  //当前状态更新前的处理

                currentState = state;            //更新到该状态

                currentState.DoBeforeEntering(); //当前状态进入前的处理

                break;
            }
        }
    }
Exemplo n.º 10
0
        // 该方法基于当前状态和过渡状态是否通过来尝试改变状态机的状态,当前状态没有目标状态过渡时则打印错误信息
        // 切换当前状态到下一个要转换的状态
        public void PerformTransition(Transition trans)
        {
            if (trans == Transition.NullTransition)
            {
                Debug.LogError("FSM error:NullTransition is not allowed");
                return;
            }

            StateId id = _currentFsmState.GetOutputState(trans);

            if (id == StateId.NullStateId)
            {
                Debug.LogError("FSM error: State " + _currentFsmState.ID.ToString() + "does not allowed");
                return;
            }

            //更新当前的状态机和状态编号
            _currentStateId = id;
            foreach (FSMState state in states)
            {
                if (state.ID == _currentStateId)
                {
                    _currentFsmState.DoBeforeLeaving();
                    _currentFsmState = state;
                    _currentFsmState.DoBeforeEntering();
                    break;
                }
            }
        }
Exemplo n.º 11
0
    /// <summary>
    /// Tries to change the state of the FSM based on the current state
    /// and the given transition.
    /// If the current state does not have a target state for the passed transition,
    /// no transition will be performed.
    /// </summary>
    /// <param name="transition">Transition</param>
    public void PerformTransition(Transition transition)
    {
        // StateID of the desired transition.
        StateID id = currentState.GetOutputState(transition);

        if (transition == Transition.NullTransition)
        {
            Debug.LogError("FSMState: NullTransition is not allowed.");
        }
        else if (id == StateID.NullStateID)
        {
            Debug.LogError("FSMState: State " + currentStateID.ToString() + " does not have a target state for transition " + transition.ToString());
        }
        else
        {
            // Change current state
            currentStateID = id;

            foreach (FSMState state in states)
            {
                if (state.ID == currentStateID)
                {
                    // Call processing before leaving.
                    currentState.DoBeforeLeaving();

                    //Change current state.
                    currentState = state;

                    //Call proceccing after entering.
                    currentState.DoBeforeEntering();
                    break;
                }
            }
        }
    }
Exemplo n.º 12
0
    // next method tries to chage the state the fsm is in based on the current state
    //and the transition passed in. If the current state doesnt have a target state for the transition passed,
    // prints an error message
    public void PerformTransition(Transition trans)
    {
        if (trans == Transition.NullTransition)
        {
            Debug.LogError("FSM error, NullTransition is not allowed for a real transition");
            return;
        }
        // look at current state
        // see if it has the transition passed as an argument
        StateID id = currentState.GetOutputState(trans); // using method created above

        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 the currentState
        currentStateID = id;
        foreach (FSMState state in states)
        {
            if (state.ID == currentStateID)
            {
                // post processes to do to the state before setting a new one
                currentState.DoBeforeLeaving();
                currentState = state;

                // reset the state to its condition before is can be enacted (reasoning steps included)
                currentState.DoBeforeEntering();
                break;
            }
        } // performTranition()
    }     // class FSMSystem()
Exemplo n.º 13
0
    public void PerformTransition(Transition trans)
    {
        if (isTransition)
        {
            return;
        }



        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)
        {
            return;
        }

        _NextStateID = id;



        foreach (FSMState state in States)
        {
            if (state.ID == _NextStateID)
            {
                _TransitionDuration = _CurrentState.dic[trans];
                _CurrentState.DoBeforeLeaving();
                _CurrentState = null;
                state.DoBeforeEnter();
                isTransition = true;
                CoroutineTaskManager.Instance.WaitSecondTodo(() =>
                {
                    _CurrentState = state;
                    isTransition  = false;
                }, _TransitionDuration);
                break;
            }
        }
    }
Exemplo n.º 14
0
    /// <summary>
    /// 基于转换参数,改变现在的状态
    /// </summary>
    /// <param name="trans"></param>
    public void PerformTransition(Transition trans)
    {
        // 根绝当前的状态类,以Trans为参数调用它的 GetOutputState 方法
        StateID id = currentState.GetNextState(trans);

        // 更新现在的状态
        currentStateID = id;
        FSMState fs;

        if (states.TryGetValue(currentStateID, out fs))
        {
            currentState.DoBeforeLeaving();
            currentState = fs;
            currentState.DoBeforeEntering();
        }
        else
        {
            Debug.LogError("FSM CHANGE ERROR: The FsmSystem is not contain the FsmState.");
            return;
        }
    }
Exemplo n.º 15
0
    /// <summary>
    /// 该方法基于当前状态和过渡状态是否通过来尝试改变状态机的状态,当当前状态没有目标状态用来过渡时则打印错误信息
    /// 切换当前状态到下一个要转换的状态
    /// </summary>
    /// <param name="trans"></param>
    public void ChangeState(int id)
    {
        if (!states.ContainsKey(id))
        {
            Debug.LogError("FSM error: State " + id + "not exist.");
            return;
        }

        //更新当前的状态机和状态编号
        currentStateID = id;
        //在状态变为新状态前执行后处理
        if (currentFSMState != null)
        {
            currentFSMState.DoBeforeLeaving();
        }

        currentFSMState = states[id];

        //在状态可以使用Reason(动机)或者Act(行为)之前为它的决定条件重置它自己
        currentFSMState.DoBeforeEntering();
    }
Exemplo n.º 16
0
    //控制状态之间的转换
    public void PreformTransition(Transition trans)
    {
        if (trans == Transition.NullTransition)
        {
            Debug.LogError("NullTransition is not allowed for real transition ");
            return;
        }
        StateID id = currentState.GetOutputState(trans);

        if (id == StateID.NullStateID)
        {
            Debug.Log("Transition is not to be happened!没有符合条件的转换");
            return;
        }
        FSMState state;

        states.TryGetValue(id, out state);
        currentState.DoBeforeLeaving();
        currentState = state;
        currentState.DoBeforeEntering();
    }
Exemplo n.º 17
0
    /// <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(PersonState personState, string actionData)
    {
        // Check for NullTransition before changing the current state
        if (personState == PersonState.None)
        {
            Debug.Log("FSM ERROR: NullTransition is not allowed for a real transition");
            return;
        }

        // Check if the currentState has the transition passed as argument
        StateID id = currentState.GetOutputState(personState);

        if (id == StateID.NoneStateId)

        {
            Debug.Log("FSM ERROR: State " + currentStateID.ToString() + " does not have a target state " +
                      " for transition " + personState.ToString());
            return;
        }

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

                currentState      = state;
                currentState.data = actionData;

                currentState.HandleData();
                // Reset the state to its desired condition before it can reason or act
                currentState.DoBeforeEntering();
                break;
            }
        }
    } // PerformTransition()
Exemplo n.º 18
0
    public void PerformTransition(string trans)
    {
        if (trans == nullTransition)
        {
            Debug.LogError("FSM ERROR: NullTransition is not allowed for a real transition");
            return;
        }

        string id = currentState.GetOutputState(trans);

        Debug.Log("Got transition " + trans);
        Debug.Log("And output state is " + id);
        if (id == nullState)
        {
            Debug.LogError("FSM ERROR: State " + currentStateID.ToString() + " does not have a target state " +
                           " for transition " + trans.ToString());
            return;
        }

        currentStateID = id;
        bool found = false;

        foreach (FSMState state in states)
        {
            if (state.ID == currentStateID)
            {
                found = true;
                currentState.DoBeforeLeaving();
                currentState = state;
                currentState.DoBeforeEntering();
                break;
            }
        }
        if (!found)
        {
            Debug.LogError("FSM ERROR: state " + currentStateID + " not found. Maybe you are missing the implementation");
        }
    }
Exemplo n.º 19
0
    public void PerformTransition(Transition trans)
    {
        if (trans == Transition.NullTransition)
        {
            Debug.LogError("要执行的转换条件为空"); return;
        }
        StateID nextStateID = mCurrentState.GetOutPutState(trans);

        if (nextStateID == StateID.NullState)
        {
            Debug.LogError("没有对应可转换状态"); return;
        }
        foreach (FSMState s in mStates)
        {
            if (s.stateID == nextStateID)
            {
                mCurrentState.DoBeforeLeaving();
                mCurrentState = s;
                mCurrentState.DoBeforeEntering();
                break;
            }
        }
    }
Exemplo n.º 20
0
    public void PerformTransition(Transition trans)
    {
        if (trans == Transition.NullTransition)
        {
            TraceUtil.Log(SystemModel.Common, TraceLevel.Error, "FSM ERROR:NullTransition is not allowed for a real transition");
            return;
        }

        StateID id = m_currentState.GetOutputState(trans);

        if (id == StateID.NullStateID)
        {
            TraceUtil.Log(SystemModel.Common, TraceLevel.Error, "FSM ERROR: State " + m_currentStateID.ToString() + " does not have a target state for transition " + trans.ToString());

            return;
        }
        if (m_allowStateChange != null && !m_allowStateChange(trans))
        {
            return;
        }
        m_previourStateID = m_currentStateID;
        m_currentStateID  = id;
        foreach (FSMState state in m_states)
        {
            if (state.StateID == m_currentStateID)
            {
                m_currentState.DoBeforeLeaving();
                m_currentState = state;
                if (OnPerformTransition != null)
                {
                    OnPerformTransition(trans);
                }
                m_currentState.DoBeforeEntering();
                break;
            }
        }
    }
Exemplo n.º 21
0
    /// 执行转换过渡
    public void PerformTransition(Transition trans)
    {
        // 空值检验
        if (trans == Transition.NullTransition)
        {
            Debug.LogError("FSM ERROR: 转换不可为空");
            return;
        }

        // 获取当前状态ID
        StateID id = currentState.GetOutputState(trans);

        if (id == StateID.NullStateID)
        {
            Debug.LogError("FSM ERROR: 状态 " + currentStateID.ToString() + " 不存在目标状态 " +
                           " - 转换: " + trans.ToString());
            return;
        }

        // 更新当前状态ID 与 当前状态
        currentStateID = id;
        foreach (FSMState state in states)
        {
            if (state.ID == currentStateID)
            {
                // 执行当前状态后处理
                currentState.DoBeforeLeaving();

                currentState = state;

                // 执行当前状态前处理
                currentState.DoBeforeEntering();
                break;
            }
        }
    }