示例#1
0
    public virtual void SetRestingState(Substate newState)
    {
        // 1. Lock transitions.
        canTransition = false;

        // 2. Cleanup all the active Substates
        for (int i = pushdownStates.Count - 1; i >= 0; i--)
        {
            // Make sure exit state is called
            if (!pushdownStates[i].Interruptable)
            {
                pushdownStates[i].OnStateExit(this);
            }
            pushdownStates.RemoveAt(i);
            pushdownExpirationTimes.RemoveAt(i);
        }

        // 3. Set the resting state
        restingState = newState;

        // 4. Set the current finite state
        if (finiteState != null)
        {
            finiteState.OnStateExit(this);
        }

        finiteState = restingState;
        finiteState.OnStateEnter(this);
        transitionTime = SetTimer(finiteState);

        // 5. Unlock transitions
        canTransition = true;
    }
示例#2
0
    public virtual void RemoveSubstate(Substate oldState, bool interruptState = false)
    {
        // Given that the state exists in the list ...
        if (pushdownStates.Contains(oldState))
        {
            // Find the index of the state and it's expiration time.
            int stateIndex = pushdownStates.FindIndex(oldState.Equals);
            // Debug.Log(oldState + " found at index " + stateIndex);

            // Call it's Exit method, given the Substate is not interrupted.
            if (interruptState && oldState.Interruptable)
            {
                Debug.Log(oldState.name + " was interrupted. ");
            }
            else
            {
                oldState.OnStateExit(this);
            }

            // Remove both the state and it's expiration time from respective collections.
            pushdownExpirationTimes.RemoveAt(stateIndex);
            pushdownStates.RemoveAt(stateIndex);
        }
    }