1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use bevy::prelude::*;
use bevy_input_bindings::ots::ui::*;
use bevy_input_bindings::prelude::*;
fn main() {
App::new()
.add_plugins((
DefaultPlugins,
// Add the OTS UI plugins
OtsUiGamepadPlugin::new(),
OtsUiKeyboardPlugin::new(),
))
// Add an observer to print the inputs. It will catch events for the `OtsUiActions` actions,
// find the `ControllerInterface` that sent it, and print the event data.
.add_observer(
|action: On<ActionEvent<OtsUiActions>>, controllers: Query<&ControllerInterface>| {
// Find the controller that sent the event
let Ok(controller) = controllers.get(action.controller()) else {
return;
};
// Print data about this action
println!(
"Action from {}({:?}): {:?}",
action.controller(),
controller.layout(),
action.key()
);
},
)
// Add a startup system to setup a camera. The Gamepad binders will be automatically added
// at gamepad connection.
.add_systems(Startup, |mut commands: Commands| {
commands.spawn(Camera2d::default());
commands.spawn(OtsUiKeyboardBinding::new());
})
.run();
}