 bcc33f6757
			
		
	
	
		bcc33f6757
		
	
	
	
	
		
			
			# Objective Fixes #6339. ## Solution This PR adds a new type, `GamepadInfo`, which holds metadata associated with a particular `Gamepad`. The `Gamepads` resource now holds a `HashMap<Gamepad, GamepadInfo>`. The `GamepadInfo` is created when the gamepad backend (by default `bevy_gilrs`) emits a "gamepad connected" event. The `gamepad_viewer` example has been updated to showcase the new functionality. Before:  After:  --- ## Changelog ### Added - Added `GamepadInfo`. - Added `Gamepads::name()`, which returns the name of the specified gamepad if it exists. ### Changed - `GamepadEventType::Connected` is now a tuple variant with a single field of type `GamepadInfo`. - Since `GamepadInfo` is not `Copy`, `GamepadEventType` is no longer `Copy`. The same is true of `GamepadEvent` and `GamepadEventRaw`. ## Migration Guide - Pattern matches on `GamepadEventType::Connected` will need to be updated, as the form of the variant has changed. - Code that requires `GamepadEvent`, `GamepadEventRaw` or `GamepadEventType` to be `Copy` will need to be updated.
		
			
				
	
	
		
			39 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
| //! Iterates and prints gamepad input and connection events.
 | |
| 
 | |
| use bevy::{
 | |
|     input::gamepad::{GamepadEvent, GamepadEventType},
 | |
|     prelude::*,
 | |
| };
 | |
| 
 | |
| fn main() {
 | |
|     App::new()
 | |
|         .add_plugins(DefaultPlugins)
 | |
|         .add_system(gamepad_events)
 | |
|         .run();
 | |
| }
 | |
| 
 | |
| fn gamepad_events(mut gamepad_event: EventReader<GamepadEvent>) {
 | |
|     for event in gamepad_event.iter() {
 | |
|         match event.event_type {
 | |
|             GamepadEventType::Connected(_) => {
 | |
|                 info!("{:?} Connected", event.gamepad);
 | |
|             }
 | |
|             GamepadEventType::Disconnected => {
 | |
|                 info!("{:?} Disconnected", event.gamepad);
 | |
|             }
 | |
|             GamepadEventType::ButtonChanged(button_type, value) => {
 | |
|                 info!(
 | |
|                     "{:?} of {:?} is changed to {}",
 | |
|                     button_type, event.gamepad, value
 | |
|                 );
 | |
|             }
 | |
|             GamepadEventType::AxisChanged(axis_type, value) => {
 | |
|                 info!(
 | |
|                     "{:?} of {:?} is changed to {}",
 | |
|                     axis_type, event.gamepad, value
 | |
|                 );
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| }
 |