public bool ChangeState <T>() where T : StateBaseV2 { var stateIndex = availableStates.FindIndex(x => x.GetType() == typeof(T)); if (stateIndex < 0) { Console.WriteLine("Error: State not found"); return(false); } else { if (currentState.AvailableTransition <T>()) { previousState = currentState; currentState = availableStates[stateIndex]; Console.WriteLine($"New State: {currentState.name}"); return(true); } else { Console.WriteLine($"We can't change state from {currentState.name} to {typeof(T).Name}"); return(false); } } }
public void AddState(StateBaseV2 state) { var sameState = availableStates.Any(x => x.GetType() == state.GetType()); if (sameState) { Console.WriteLine("Error: Same State Type"); return; } availableStates.Add(state); }