public virtual TState State <TState>() where TState : IState { IState state; if (!Cache.Get <TState>(out state)) { //state = new TState(); state = m_StateFactory.Get <TState>(m_StateInitializationParams); Cache.Add(state); } return((TState)state); }
/// <inheritdoc /> public virtual void ChangeState(Type type) { var state = _factory.Get(type); if (CurrentState == null) { CurrentState = state; CurrentState.Start(null); return; } if (!CurrentState.CanMoveToState(type)) { #if UNITY_EDITOR throw new ArgumentOutOfRangeException( nameof(type), type, $"{CurrentState.GetType().Name} tried to move to {state.GetType().Name}" ); #else Debug.LogException( new ArgumentOutOfRangeException( nameof(type), type, $"{CurrentState.GetType().Name} tried to move to {state.GetType().Name}" ) ); return; #endif } CurrentState.Exit(); LastStateType = CurrentState.GetType(); CurrentState = state; CurrentState.Start(LastStateType); }