コード例 #1
0
ファイル: FSM.cs プロジェクト: niksok13/NSTools
 /// <summary>
 /// Change state
 /// </summary>
 /// <param name="newState">State to go</param>
 public void Go(AState newState)
 {
     if (newState == null)
     {
         return;
     }
     Log.Info($"FSM:Go({newState})");
     currentState?.Exit();
     currentState = newState;
     currentState.Enter();
 }
コード例 #2
0
    // State management
    public void SwitchState(string newState)
    {
        AState state = FindState(newState);

        if (state == null)
        {
            Debug.LogError("Can't find the state named " + newState);
            return;
        }

        m_StateStack[m_StateStack.Count - 1].Exit(state);
        state.Enter(m_StateStack[m_StateStack.Count - 1]);
        m_StateStack.RemoveAt(m_StateStack.Count - 1);
        m_StateStack.Add(state);
    }
コード例 #3
0
    public void Push(AState stateInstance)
    {
        if (stateInstance.Stackable || !StateStack.Any(x => x.Id == stateInstance.Id))
        {
            StateStack.Add(stateInstance);
            WaitingToFinish = true;

            AState currentState = Top(StateStack);
            if (currentState != null)
            {
                currentState.Enter();
            }
        }
        else
        {
            Debug.Log("Duplicate state tried to be pushed:");
            Debug.Log(stateInstance.Id);
        }
    }
コード例 #4
0
    // 游戏状态间的切换
    public void SwitchState(string newState)
    {
        //新的状态
        AState state = FindState(newState);

        if (state == null)
        {
            Debug.LogError("Can't find the state named " + newState);
            return;
        }

        //先退出之前最顶部的状态
        m_StateStack[m_StateStack.Count - 1].Exit(state);

        //新的状态进来
        state.Enter(m_StateStack[m_StateStack.Count - 1]);

        //状态数组中移除之前的状态
        m_StateStack.RemoveAt(m_StateStack.Count - 1);

        //状态数组添加新的状态
        m_StateStack.Add(state);
    }
コード例 #5
0
    public void ChangeState(string newState, float delayBetweenState = 0)
    {
        if (newState == null)
        {
            _activeState.Exit();
            _activeState = null;
            return;
        }

        _activeState.Exit();
        _activeState = FindState(newState);

        if (delayBetweenState == 0)
        {
            _activeState.Enter();
        }
        else
        {
            Timer.Add(delayBetweenState, _activeState.Enter);
        }

        Debug.Log("Current Game State - " + _activeState);
    }
コード例 #6
0
ファイル: FiniteStateMachine.cs プロジェクト: Piechota/LD40
    public void TransitionTo(int nextStateId)
    {
        AState prevState = GetCurrentState();
        AState nextState = GetState(nextStateId);

        if (prevState != null)
        {
            prevState.Leave(nextState);
        }

        CurrentStateId = nextStateId;

        if (nextState != null)
        {
            nextState.Enter(prevState);
        }
        else
        {
            CurrentStateId = AState.INVALID_STATE;
        }

        OnStateChanged.Invoke();
        OnHierarchyChanged.Invoke();
    }
コード例 #7
0
 public void InstanceState(string stateName)
 {
     _activeState = FindState(stateName);
     _activeState.Enter();
     Debug.Log("Init state " + _activeState.GetName());
 }