Example #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);
    }
Example #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);
    }
Example #3
0
    public bool ForceReenterState()
    {
        previousState = currentState;

        if (currentState.OnEnter != null)
        {
            currentState.OnEnter(owner);
        }

        if (OnChange != null)
        {
            OnChange(previousState.idx, currentState.idx);
        }
        return(true);
    }