Esempio n. 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;
    }
Esempio n. 2
0
    // Transition from the current finite state to a new one, calling OnStateEnter
    protected void TransitionState(Substate newState)
    {
        // 1. Call exit function of current state
        finiteState.OnStateExit(this);

        // 2. Set the new current state.
        finiteState = Instantiate(newState);
        finiteState.OnStateEnter(this);
        transitionTime = SetTimer(newState);
    }
Esempio n. 3
0
 public virtual void AddSubstate(Substate newState)
 {
     // Add the new state if it's not in the list
     if (!pushdownStates.Contains(newState))
     {
         pushdownStates.Add(newState);
         pushdownExpirationTimes.Add(SetTimer(newState));
         newState.OnStateEnter(this);
     }
     else
     {
         // Refresh the state if it's found in the list.
         RefreshState(newState);
     }
 }