示例#1
0
    /// <summary>
    /// Sets the next state in the state machine, clears up the previous state
    /// and calls OnEnter for the new state
    /// </summary>
    protected void SetState(IEntityState nextState)
    {
        // Exit previous state
        if (currentState != null)
        {
            currentState.OnExit();
        }

        currentState = nextState;

        if (currentState != null)
        {
            currentState.OnEnter(this);

            if (stateCompleteCheck == null)
            {
                stateCompleteCheck = StartCoroutine(CheckComplete());
            }
        }
        else
        {
            if (stateCompleteCheck != null)
            {
                StopCoroutine(stateCompleteCheck);
                stateCompleteCheck = null;
            }
        }
    }