private IEnumerator ChangeToNewStateRoutine(StateMapping newState) { isInTransition = true; foreach (StateMapping currentState in currentStates) { if (currentState != null) { var exitRoutine = currentState.Exit(); if (exitRoutine != null) { yield return(StartCoroutine(exitRoutine)); } } } currentStates = new List <StateMapping>(); currentStates.Add(newState); if (newState != null) { var enterRoutine = newState.Enter(); if (enterRoutine != null) { yield return(StartCoroutine(enterRoutine)); } } isInTransition = false; }
private IEnumerator AddConcurrentStateRoutine(StateMapping newState) { currentStates.Add(newState); if (newState != null) { var enterRoutine = newState.Enter(); if (enterRoutine != null) { yield return(StartCoroutine(enterRoutine)); } } }
IEnumerator ChangeToNewStateRoutine(StateMapping newState) { destinationState = newState; // Chache this so that we can overwrite it and hijack a transition if (currentState != null) { exitRoutine = currentState.Exit(); if (exitRoutine != null) { yield return(StartCoroutine(exitRoutine)); } exitRoutine = null; currentState.Finally(); } currentState = destinationState; if (currentState != null) { enterRoutine = currentState.Enter(); if (enterRoutine != null) { yield return(StartCoroutine(enterRoutine)); } enterRoutine = null; // Broadcast change only after enter transition has begun. if (Changed != null) { Changed(currentState.state); } } isInTransition = false; }