// TODO: Maybe reduce it to only the inputs actually used in the game? private void MapPlayerInput(InputMapper inputMapper, GamePadState state, GamePadState previousState) { foreach (int axisInt in InputMapperAsset.GetMappedXboxAxis()) { MapXboxAxis(axisInt, inputMapper, state); } foreach (int buttonInt in InputMapperAsset.GetMappedXboxButtons()) { MapXboxButton(buttonInt, inputMapper, state, previousState); } // TODO: Put the following code into another class, so we can have 2 distinct XboxManager and KeyboardManager classes // We map only the keyboard keys that are going to be used in the game foreach (int key in InputMapperAsset.GetMappedKeyboardKeys()) { inputMapper.SetRawButtonState(100 + key, Input.GetKey((KeyCode)key), Input.GetKey((KeyCode)key) && !Input.GetKeyDown((KeyCode)key)); } foreach (int key in InputMapperAsset.GetMappedKeyboardKeysAxis()) { float value = Input.GetKey((KeyCode)key) ? 1f : 0f; inputMapper.SetRawAxisValue(100 + key, value); } }
// TODO: Maybe reduce it to only the inputs actually used in the game? private void MapPlayerInput(InputMapper inputMapper, GamePadState state, GamePadState previousState) { foreach (int axisInt in InputMapperAsset.GetMappedXboxAxis()) { MapXboxAxis(axisInt, inputMapper, state); } foreach (int buttonInt in InputMapperAsset.GetMappedXboxButtons()) { MapXboxButton(buttonInt, inputMapper, state, previousState); } // TODO: Put the following code into another class, so we can have 2 distinct XboxManager and KeyboardManager classes // We map only the keyboard keys that are going to be used in the game foreach (int key in InputMapperAsset.GetMappedKeyboardKeys()) { inputMapper.SetRawButtonState(100 + key, Input.GetKey((KeyCode)key), Input.GetKey((KeyCode)key) && !Input.GetKeyDown((KeyCode)key)); } foreach (int key in InputMapperAsset.GetMappedKeyboardKeysAxis()) { float value = Input.GetKey((KeyCode)key) ? 1f : 0f; inputMapper.SetRawAxisValue(100 + key, value); } }
private void MapXboxButton(int buttonInt, InputMapper inputMapper, GamePadState state, GamePadState previousState) { XboxInputConstants.Buttons button = (XboxInputConstants.Buttons)buttonInt; bool pressed = false; bool previouslyPressed = false; switch (button) { case XboxInputConstants.Buttons.A: pressed = state.Buttons.A == ButtonState.Pressed; previouslyPressed = previousState.Buttons.A == ButtonState.Pressed; break; case XboxInputConstants.Buttons.B: pressed = state.Buttons.B == ButtonState.Pressed; previouslyPressed = previousState.Buttons.B == ButtonState.Pressed; break; case XboxInputConstants.Buttons.X: pressed = state.Buttons.X == ButtonState.Pressed; previouslyPressed = previousState.Buttons.X == ButtonState.Pressed; break; case XboxInputConstants.Buttons.Y: pressed = state.Buttons.Y == ButtonState.Pressed; previouslyPressed = previousState.Buttons.Y == ButtonState.Pressed; break; case XboxInputConstants.Buttons.LeftShoulder: pressed = state.Buttons.LeftShoulder == ButtonState.Pressed; previouslyPressed = previousState.Buttons.LeftShoulder == ButtonState.Pressed; break; case XboxInputConstants.Buttons.RightShoulder: pressed = state.Buttons.RightShoulder == ButtonState.Pressed; previouslyPressed = previousState.Buttons.RightShoulder == ButtonState.Pressed; break; case XboxInputConstants.Buttons.Back: pressed = state.Buttons.Back == ButtonState.Pressed; previouslyPressed = previousState.Buttons.Back == ButtonState.Pressed; break; case XboxInputConstants.Buttons.Start: pressed = state.Buttons.Start == ButtonState.Pressed; previouslyPressed = previousState.Buttons.Start == ButtonState.Pressed; break; case XboxInputConstants.Buttons.LeftStick: pressed = state.Buttons.LeftStick == ButtonState.Pressed; previouslyPressed = previousState.Buttons.LeftStick == ButtonState.Pressed; break; case XboxInputConstants.Buttons.RightStick: pressed = state.Buttons.RightStick == ButtonState.Pressed; previouslyPressed = previousState.Buttons.RightStick == ButtonState.Pressed; break; case XboxInputConstants.Buttons.DPadLeft: pressed = state.DPad.Left == ButtonState.Pressed; previouslyPressed = previousState.DPad.Left == ButtonState.Pressed; break; case XboxInputConstants.Buttons.DPadRight: pressed = state.DPad.Right == ButtonState.Pressed; previouslyPressed = previousState.DPad.Right == ButtonState.Pressed; break; case XboxInputConstants.Buttons.DPadUp: pressed = state.DPad.Up == ButtonState.Pressed; previouslyPressed = previousState.DPad.Up == ButtonState.Pressed; break; case XboxInputConstants.Buttons.DPadDown: pressed = state.DPad.Down == ButtonState.Pressed; previouslyPressed = previousState.DPad.Down == ButtonState.Pressed; break; } inputMapper.SetRawButtonState(buttonInt, pressed, previouslyPressed); }
private void MapXboxButton(int buttonInt, InputMapper inputMapper, GamePadState state, GamePadState previousState) { XboxInputConstants.Buttons button = (XboxInputConstants.Buttons)buttonInt; bool pressed = false; bool previouslyPressed = false; switch (button) { case XboxInputConstants.Buttons.A: pressed = state.Buttons.A == ButtonState.Pressed; previouslyPressed = previousState.Buttons.A == ButtonState.Pressed; break; case XboxInputConstants.Buttons.B: pressed = state.Buttons.B == ButtonState.Pressed; previouslyPressed = previousState.Buttons.B == ButtonState.Pressed; break; case XboxInputConstants.Buttons.X: pressed = state.Buttons.X == ButtonState.Pressed; previouslyPressed = previousState.Buttons.X == ButtonState.Pressed; break; case XboxInputConstants.Buttons.Y: pressed = state.Buttons.Y == ButtonState.Pressed; previouslyPressed = previousState.Buttons.Y == ButtonState.Pressed; break; case XboxInputConstants.Buttons.LeftShoulder: pressed = state.Buttons.LeftShoulder == ButtonState.Pressed; previouslyPressed = previousState.Buttons.LeftShoulder == ButtonState.Pressed; break; case XboxInputConstants.Buttons.RightShoulder: pressed = state.Buttons.RightShoulder == ButtonState.Pressed; previouslyPressed = previousState.Buttons.RightShoulder == ButtonState.Pressed; break; case XboxInputConstants.Buttons.Back: pressed = state.Buttons.Back == ButtonState.Pressed; previouslyPressed = previousState.Buttons.Back == ButtonState.Pressed; break; case XboxInputConstants.Buttons.Start: pressed = state.Buttons.Start == ButtonState.Pressed; previouslyPressed = previousState.Buttons.Start == ButtonState.Pressed; break; case XboxInputConstants.Buttons.LeftStick: pressed = state.Buttons.LeftStick == ButtonState.Pressed; previouslyPressed = previousState.Buttons.LeftStick == ButtonState.Pressed; break; case XboxInputConstants.Buttons.RightStick: pressed = state.Buttons.RightStick == ButtonState.Pressed; previouslyPressed = previousState.Buttons.RightStick == ButtonState.Pressed; break; case XboxInputConstants.Buttons.DPadLeft: pressed = state.DPad.Left == ButtonState.Pressed; previouslyPressed = previousState.DPad.Left == ButtonState.Pressed; break; case XboxInputConstants.Buttons.DPadRight: pressed = state.DPad.Right == ButtonState.Pressed; previouslyPressed = previousState.DPad.Right == ButtonState.Pressed; break; case XboxInputConstants.Buttons.DPadUp: pressed = state.DPad.Up == ButtonState.Pressed; previouslyPressed = previousState.DPad.Up == ButtonState.Pressed; break; case XboxInputConstants.Buttons.DPadDown: pressed = state.DPad.Down == ButtonState.Pressed; previouslyPressed = previousState.DPad.Down == ButtonState.Pressed; break; } inputMapper.SetRawButtonState(buttonInt, pressed, previouslyPressed); }