示例#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
    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);
    }
示例#3
0
    public void Update()
    {
        AState currentState = Top(StateStack);

        if (currentState != null)
        {
            currentState.Update();

            if (currentState.IsComplete)
            {
                currentState.Exit();
                StateStack = StateStack.Where(x => !x.IsComplete).ToList();

                /* We don't enter in the same loop as an exit, or the states may conflict. */
                currentState = Top(StateStack);

                WaitingToFinish = currentState == null;
            }
        }
    }