public void Update() { _keyboardPrevious = _keyboardCurrent; _keyboardCurrent = Keyboard.GetState(); _mousePrevious = _mouseCurrent; _mouseCurrent = Mouse.GetState(); for (int i = 0; i < GamePad.MaximumGamePadCount; i++) { _gamepadPrevious[i] = _gamepadCurrent[i]; _gamepadCurrent[i] = GamePad.GetState(i); if (_gamepadCurrent[i].IsConnected != _gamepadPrevious[i].IsConnected) { if (_gamepadCurrent[i].IsConnected) { _connectedGamePads.Add(i); GamePadConnected?.Invoke(this, i); } else { _connectedGamePads.Remove(i); GamePadDisconnected?.Invoke(this, i); } } } }
/// <summary> /// Raises the <see cref="GamePadDisconnected"/> event. /// </summary> /// <param name="device">The device that was disconnected.</param> /// <param name="playerIndex">The player index associated with the game pad.</param> private void OnGamePadDisconnected(GamePadDevice device, Int32 playerIndex) { if (primaryGamePad == device) { primaryGamePad = null; } GamePadDisconnected?.Invoke(device, playerIndex); }
public void Update() { _previousKeyboardState = _currentKeyboardState; _currentKeyboardState = Keyboard.GetState(); _previousMouseState = _currentMouseState; _currentMouseState = Mouse.GetState(); for (int i = 0; i < SUPPORTED_GAMEPAD_COUNT; i++) { _previousGamePadStates[i] = _currentGamePadStates[i]; _currentGamePadStates[i] = GamePad.GetState(i); if (_currentGamePadStates[i].IsConnected && !_previousGamePadStates[i].IsConnected) { GamePadConnected?.Invoke(i); } if (!_currentGamePadStates[i].IsConnected && _previousGamePadStates[i].IsConnected) { GamePadDisconnected?.Invoke(i); } } }
/// <summary> /// Raises the <see cref="GamePadDisconnected"/> event. /// </summary> /// <param name="device">The device that was disconnected.</param> /// <param name="playerIndex">The player index associated with the game pad.</param> private void OnGamePadDisconnected(GamePadDevice device, Int32 playerIndex) => GamePadDisconnected?.Invoke(device, playerIndex);