Struct bevy_internal::input::gamepad::GamepadEventRaw
source · pub struct GamepadEventRaw {
pub gamepad: Gamepad,
pub event_type: GamepadEventType,
}Expand description
A raw event of a Gamepad.
This event is the translated version of the EventType from the GilRs crate.
It is available to the end user and can be used for game logic.
Differences
The difference between the EventType from the GilRs crate and the GamepadEventRaw
is that the latter has less events, because the button pressing logic is handled through the generic
Input<T> instead of through events.
The difference between the GamepadEventRaw and the GamepadEvent can be seen in the documentation
of the GamepadEvent.
Gamepad input mocking
The following example showcases how to mock gamepad input by manually sending GamepadEventRaws.
#[derive(Resource)]
struct MyResource(bool);
// This system sets the bool inside `MyResource` to `true` if the `South` button of the first gamepad is pressed.
fn change_resource_on_gamepad_button_press(
mut my_resource: ResMut<MyResource>,
gamepads: Res<Gamepads>,
button_inputs: ResMut<Input<GamepadButton>>,
) {
let gamepad = gamepads.iter().next().unwrap();
let gamepad_button = GamepadButton::new(gamepad, GamepadButtonType::South);
my_resource.0 = button_inputs.pressed(gamepad_button);
}
// Create our app.
let mut app = App::new();
// Add the input plugin and the system/resource we want to test.
app.add_plugin(InputPlugin)
.insert_resource(MyResource(false))
.add_system(change_resource_on_gamepad_button_press);
// Define our dummy gamepad input data.
let gamepad = Gamepad::new(0);
let button_type = GamepadButtonType::South;
// Send the gamepad connected event to mark our gamepad as connected.
// This updates the `Gamepads` resource accordingly.
let info = GamepadInfo { name: "Mock Gamepad".into() };
app.world.send_event(GamepadEventRaw::new(gamepad, GamepadEventType::Connected(info)));
// Send the gamepad input event to mark the `South` gamepad button as pressed.
// This updates the `Input<GamepadButton>` resource accordingly.
app.world.send_event(GamepadEventRaw::new(
gamepad,
GamepadEventType::ButtonChanged(button_type, 1.0)
));
// Advance the execution of the schedule by a single cycle.
app.update();
// At this point you can check if your game logic corresponded correctly to the gamepad input.
// In this example we are checking if the bool in `MyResource` was updated from `false` to `true`.
assert!(app.world.resource::<MyResource>().0);
// Send the gamepad input event to mark the `South` gamepad button as released.
// This updates the `Input<GamepadButton>` resource accordingly.
app.world.send_event(GamepadEventRaw::new(
gamepad,
GamepadEventType::ButtonChanged(button_type, 0.0)
));
// Advance the execution of the schedule by another cycle.
app.update();
// Check if the bool in `MyResource` was updated from `true` to `false`.
assert!(!app.world.resource::<MyResource>().0);Fields§
§gamepad: GamepadThe gamepad this event corresponds to.
event_type: GamepadEventTypeThe type of the event.
Implementations§
source§impl GamepadEventRaw
impl GamepadEventRaw
sourcepub fn new(gamepad: Gamepad, event_type: GamepadEventType) -> GamepadEventRaw
pub fn new(gamepad: Gamepad, event_type: GamepadEventType) -> GamepadEventRaw
Creates a new GamepadEventRaw.
Trait Implementations§
source§impl Clone for GamepadEventRaw
impl Clone for GamepadEventRaw
source§fn clone(&self) -> GamepadEventRaw
fn clone(&self) -> GamepadEventRaw
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl Debug for GamepadEventRaw
impl Debug for GamepadEventRaw
source§impl FromReflect for GamepadEventRawwhere
Gamepad: FromReflect,
GamepadEventType: FromReflect,
impl FromReflect for GamepadEventRawwhere
Gamepad: FromReflect,
GamepadEventType: FromReflect,
source§fn from_reflect(reflect: &(dyn Reflect + 'static)) -> Option<GamepadEventRaw>
fn from_reflect(reflect: &(dyn Reflect + 'static)) -> Option<GamepadEventRaw>
Constructs a concrete instance of
Self from a reflected value.source§impl PartialEq<GamepadEventRaw> for GamepadEventRaw
impl PartialEq<GamepadEventRaw> for GamepadEventRaw
source§fn eq(&self, other: &GamepadEventRaw) -> bool
fn eq(&self, other: &GamepadEventRaw) -> bool
source§impl Reflect for GamepadEventRaw
impl Reflect for GamepadEventRaw
source§fn get_type_info(&self) -> &'static TypeInfo
fn get_type_info(&self) -> &'static TypeInfo
source§fn into_any(
self: Box<GamepadEventRaw, Global>
) -> Box<dyn Any + 'static, Global>
fn into_any(
self: Box<GamepadEventRaw, Global>
) -> Box<dyn Any + 'static, Global>
Returns the value as a
Box<dyn Any>.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Returns the value as a
&mut dyn Any.source§fn into_reflect(
self: Box<GamepadEventRaw, Global>
) -> Box<dyn Reflect + 'static, Global>
fn into_reflect(
self: Box<GamepadEventRaw, Global>
) -> Box<dyn Reflect + 'static, Global>
Casts this type to a boxed reflected value.
source§fn as_reflect(&self) -> &(dyn Reflect + 'static)
fn as_reflect(&self) -> &(dyn Reflect + 'static)
Casts this type to a reflected value.
source§fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
Casts this type to a mutable reflected value.
source§fn clone_value(&self) -> Box<dyn Reflect + 'static, Global>
fn clone_value(&self) -> Box<dyn Reflect + 'static, Global>
Clones the value as a
Reflect trait object. Read moresource§fn set(
&mut self,
value: Box<dyn Reflect + 'static, Global>
) -> Result<(), Box<dyn Reflect + 'static, Global>>
fn set(
&mut self,
value: Box<dyn Reflect + 'static, Global>
) -> Result<(), Box<dyn Reflect + 'static, Global>>
Performs a type-checked assignment of a reflected value to this value. Read more
source§fn apply(&mut self, value: &(dyn Reflect + 'static))
fn apply(&mut self, value: &(dyn Reflect + 'static))
Applies a reflected value to this value. Read more
source§fn reflect_ref(&self) -> ReflectRef<'_>
fn reflect_ref(&self) -> ReflectRef<'_>
Returns an enumeration of “kinds” of type. Read more
source§fn reflect_mut(&mut self) -> ReflectMut<'_>
fn reflect_mut(&mut self) -> ReflectMut<'_>
Returns a mutable enumeration of “kinds” of type. Read more
source§fn reflect_owned(self: Box<GamepadEventRaw, Global>) -> ReflectOwned
fn reflect_owned(self: Box<GamepadEventRaw, Global>) -> ReflectOwned
Returns an owned enumeration of “kinds” of type. Read more
source§fn reflect_partial_eq(&self, value: &(dyn Reflect + 'static)) -> Option<bool>
fn reflect_partial_eq(&self, value: &(dyn Reflect + 'static)) -> Option<bool>
Returns a “partial equality” comparison result. Read more
source§fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
Debug formatter for the value. Read more
source§fn reflect_hash(&self) -> Option<u64>
fn reflect_hash(&self) -> Option<u64>
Returns a hash of the value (which includes the type). Read more
source§fn serializable(&self) -> Option<Serializable<'_>>
fn serializable(&self) -> Option<Serializable<'_>>
Returns a serializable version of the value. Read more
source§impl Struct for GamepadEventRaw
impl Struct for GamepadEventRaw
source§fn field_at_mut(&mut self, index: usize) -> Option<&mut (dyn Reflect + 'static)>
fn field_at_mut(&mut self, index: usize) -> Option<&mut (dyn Reflect + 'static)>
Returns a mutable reference to the value of the field with index
index
as a &mut dyn Reflect. Read moresource§fn name_at(&self, index: usize) -> Option<&str>
fn name_at(&self, index: usize) -> Option<&str>
Returns the name of the field with index
index.source§fn iter_fields(&self) -> FieldIter<'_> ⓘ
fn iter_fields(&self) -> FieldIter<'_> ⓘ
Returns an iterator over the values of the reflectable fields for this struct.
source§fn clone_dynamic(&self) -> DynamicStruct
fn clone_dynamic(&self) -> DynamicStruct
Clones the struct into a
DynamicStruct.source§impl Typed for GamepadEventRaw
impl Typed for GamepadEventRaw
impl StructuralPartialEq for GamepadEventRaw
Auto Trait Implementations§
impl RefUnwindSafe for GamepadEventRaw
impl Send for GamepadEventRaw
impl Sync for GamepadEventRaw
impl Unpin for GamepadEventRaw
impl UnwindSafe for GamepadEventRaw
Blanket Implementations§
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait. Read more§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait. Read more§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s. Read more§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s. Read moresource§impl<S> GetField for Swhere
S: Struct,
impl<S> GetField for Swhere
S: Struct,
source§impl<T> GetPath for Twhere
T: Reflect,
impl<T> GetPath for Twhere
T: Reflect,
source§fn path<'r, 'p>(
&'r self,
path: &'p str
) -> Result<&'r (dyn Reflect + 'static), ReflectPathError<'p>>
fn path<'r, 'p>(
&'r self,
path: &'p str
) -> Result<&'r (dyn Reflect + 'static), ReflectPathError<'p>>
Returns a reference to the value specified by
path. Read moresource§fn path_mut<'r, 'p>(
&'r mut self,
path: &'p str
) -> Result<&'r mut (dyn Reflect + 'static), ReflectPathError<'p>>
fn path_mut<'r, 'p>(
&'r mut self,
path: &'p str
) -> Result<&'r mut (dyn Reflect + 'static), ReflectPathError<'p>>
Returns a mutable reference to the value specified by
path. Read moresource§fn get_path<T, 'r, 'p>(
&'r self,
path: &'p str
) -> Result<&'r T, ReflectPathError<'p>>where
T: Reflect,
fn get_path<T, 'r, 'p>(
&'r self,
path: &'p str
) -> Result<&'r T, ReflectPathError<'p>>where
T: Reflect,
Returns a statically typed reference to the value specified by
path.source§fn get_path_mut<T, 'r, 'p>(
&'r mut self,
path: &'p str
) -> Result<&'r mut T, ReflectPathError<'p>>where
T: Reflect,
fn get_path_mut<T, 'r, 'p>(
&'r mut self,
path: &'p str
) -> Result<&'r mut T, ReflectPathError<'p>>where
T: Reflect,
Returns a statically typed mutable reference to the value specified by
path. Read more