Пример #1
0
    public bool?SetState(BasicState nextState)
    {
        if (nextState == currentState)
        {
            return(null);
        }
        if (nextState.CanEnter(owner))
        {
            previousState = currentState;
            currentState  = nextState;
            timeInState   = 0.0f;

            if (previousState.OnExit != null)
            {
                previousState.OnExit(owner);
            }
            if (nextState.OnEnter != null)
            {
                nextState.OnEnter(owner);
            }

            if (OnChange != null)
            {
                OnChange(previousState.idx, currentState.idx);
            }
            return(true);
        }
        return(false);
    }
Пример #2
0
    public bool?SetState(BasicState nextState, bool forced = false)
    {
        if (nextState == currentState)
        {
            return(null);
        }

        if (forced || nextState.CanEnter())
        {
            failedState   = null;
            previousState = currentState;
            currentState  = nextState;

            if (previousState.OnExit != null)
            {
                previousState.OnExit(owner);
            }
            if (OnChange != null)
            {
                OnChange(previousState.idx);
            }
            if (nextState.OnEnter != null)
            {
                nextState.OnEnter(owner);
            }
            return(true);
        }
        failedState = nextState;
        return(false);
    }