public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (UIHolder.AnimatorHashes.TryGetStateByHash(stateInfo.shortNameHash, out var state)) { OnStateEntered?.Invoke(state); } }
public void SetState(IState state) { if (currentState == state) { return; } currentState?.OnExit(); OnStateExited?.Invoke(currentState); currentState = state; currentState.OnEnter(); OnStateEntered?.Invoke(currentState); }
public IEnumerator GoTo(IState nextState, bool transitionOutPreviousState = true) { if (Transitioning) { yield break; } if (ReferenceEquals(nextState, Current)) { yield break; } Transitioning = true; var previous = Current; // Transition out of the current state if (previous != null && transitionOutPreviousState) { previous.OnTransitionOut?.Invoke(nextState); OnStateTransitionOut?.Invoke(previous, nextState); yield return(previous.TransitionOut(nextState)); previous.OnExited?.Invoke(nextState); previous.Exited(nextState); OnStateExited?.Invoke(previous, nextState); previous.Sleep(nextState); } Current = nextState; // Transition in to the next state nextState.Wake(); nextState.OnTransitionIn?.Invoke(previous); OnStateTransitionIn?.Invoke(nextState, previous); yield return(nextState.TransitionIn(previous)); nextState.OnEntered?.Invoke(previous); nextState.Entered(previous); OnStateEntered?.Invoke(nextState, previous); StateEntered(nextState); Transitioning = false; }
private void Enter(GameObject state) { m_CurrentState = state; int index = m_CurrentState.transform.GetSiblingIndex(); if (index == 0) { OnFirstStateEntered?.Invoke(); } if (index == transform.childCount - 1) { OnLastStateEntered?.Invoke(); } m_CurrentState.SetActive(true); Log($"(+) {name} ENTERED state: {state.name}"); OnStateEntered?.Invoke(m_CurrentState); }
public async UniTask TransitionToState(T state) { if (CurrentTransition != null) { DebugLog("Warning: Statemachine already transitioning from " + CurrentTransition.From + " to " + CurrentTransition.To); return; } if (!firstTransition && state.Equals(CurrentState)) // depending on the type of T, currentState may already be set when we begin { DebugLog("Warning: Statemachine is already in state " + state); return; } CurrentTransition = new Transition <T>(CurrentState, state); // exiting if (!firstTransition) { CurrentTransition.Phase = TransitionPhase.EXITING_FROM; OnStateExiting?.Invoke(CurrentTransition); await states[CurrentTransition.From].OnExit(CurrentTransition.To); CurrentTransition.Phase = TransitionPhase.EXITED_FROM; OnStateExited?.Invoke(CurrentTransition); } // entering CurrentState = CurrentTransition.To; CurrentTransition.Phase = TransitionPhase.ENTERING_TO; OnStateEntering?.Invoke(CurrentTransition); await states[CurrentTransition.To].OnEnter(CurrentTransition.From); CurrentTransition.Phase = TransitionPhase.ENTERED_TO; Transition <T> prevTransition = CurrentTransition; CurrentTransition = null; OnStateEntered?.Invoke(prevTransition); firstTransition = false; }
public void StateEntered(T agent, IRandomProvider random) { OnStateEntered?.Invoke(agent, random); // Perform whatever initialization action is required }
private void OnGameStateEntered() { CurrentState.OnGameStateEnter -= OnGameStateEntered; CurrentState.OnGameStateEnterFailed -= OnFailToEnterGameState; OnStateEntered?.Invoke(CurrentState); }
private void StateMachineOnOnStateEntered(IState obj) { OnStateEntered?.Invoke(obj); }