public void SetupStateView <U>(IGameStateView <T> view) where U : GameState <T> { Type t = typeof(U); if (_viewToGameState.ContainsKey(t)) { _viewToGameState[t] = view; } else { _viewToGameState.Add(t, view); } }
private void SetGameState(Type gameStateType) { if (_currentGameState != null) { if (_currentView != null) { _currentView.EndStateView(); _currentView = null; } _currentGameState.EndState(); _gameStateHistory.Push(_currentGameState.GetType()); _currentGameState = null; } if (gameStateType == null) { return; } GameState <T> gs = Activator.CreateInstance(gameStateType) as GameState <T>; _currentGameState = gs; _currentGameState.SetupState(_game, this); if (_viewToGameState.TryGetValue(gameStateType, out _currentView)) { _currentView.PreStartStateView(_currentGameState); } _currentGameState.StartState(); if (_currentView != null) { _currentView.StartStateView(); } }