2021-12-08 20:28:08 +00:00
|
|
|
use bevy::{input::gamepad::GamepadButton, prelude::*};
|
2020-09-18 21:43:47 +00:00
|
|
|
|
|
|
|
fn main() {
|
2021-07-27 20:21:06 +00:00
|
|
|
App::new()
|
2020-11-03 03:01:17 +00:00
|
|
|
.add_plugins(DefaultPlugins)
|
2021-07-27 23:42:36 +00:00
|
|
|
.add_system(gamepad_system)
|
2020-09-18 21:43:47 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2020-10-21 17:27:00 +00:00
|
|
|
fn gamepad_system(
|
2021-12-08 20:28:08 +00:00
|
|
|
gamepads: Res<Gamepads>,
|
2020-10-21 17:27:00 +00:00
|
|
|
button_inputs: Res<Input<GamepadButton>>,
|
2020-10-15 19:45:34 +00:00
|
|
|
button_axes: Res<Axis<GamepadButton>>,
|
2020-10-21 17:27:00 +00:00
|
|
|
axes: Res<Axis<GamepadAxis>>,
|
2020-10-15 19:45:34 +00:00
|
|
|
) {
|
2021-12-08 20:28:08 +00:00
|
|
|
for gamepad in gamepads.iter().cloned() {
|
2020-10-21 22:56:07 +00:00
|
|
|
if button_inputs.just_pressed(GamepadButton(gamepad, GamepadButtonType::South)) {
|
2021-04-22 23:30:48 +00:00
|
|
|
info!("{:?} just pressed South", gamepad);
|
2020-10-21 22:56:07 +00:00
|
|
|
} else if button_inputs.just_released(GamepadButton(gamepad, GamepadButtonType::South)) {
|
2021-04-22 23:30:48 +00:00
|
|
|
info!("{:?} just released South", gamepad);
|
2020-09-18 21:43:47 +00:00
|
|
|
}
|
|
|
|
|
2020-10-21 22:56:07 +00:00
|
|
|
let right_trigger = button_axes
|
|
|
|
.get(GamepadButton(gamepad, GamepadButtonType::RightTrigger2))
|
|
|
|
.unwrap();
|
|
|
|
if right_trigger.abs() > 0.01 {
|
2021-04-22 23:30:48 +00:00
|
|
|
info!("{:?} RightTrigger2 value is {}", gamepad, right_trigger);
|
2020-10-21 22:56:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let left_stick_x = axes
|
|
|
|
.get(GamepadAxis(gamepad, GamepadAxisType::LeftStickX))
|
|
|
|
.unwrap();
|
|
|
|
if left_stick_x.abs() > 0.01 {
|
2021-04-22 23:30:48 +00:00
|
|
|
info!("{:?} LeftStickX value is {}", gamepad, left_stick_x);
|
2020-10-21 22:56:07 +00:00
|
|
|
}
|
2020-09-18 21:43:47 +00:00
|
|
|
}
|
|
|
|
}
|