/// <summary> /// Try and change to a new state /// </summary> /// <param name="type"></param> public void ChangeState(Type type) { var state = _factory.Create(type); if (CurrentState == null) { CurrentState = state; CurrentState.Start(null); return; } if (!CurrentState.CanMoveToState(state)) { Debug.LogWarningFormat( "{0} tried to move to {1}", CurrentState.GetType().Name, state.GetType().Name ); return; } CurrentState.Exit(); LastState = CurrentState; CurrentState = state; CurrentState.Start(LastState.GetType()); }
/// <summary> /// Check the last state against a type /// </summary> /// <param name="type"></param> /// <returns></returns> public bool LastStateWas(Type type) { return(LastState.GetType() == type); }