Struct bevy::input::gamepad::GamepadEventRaw
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 GamepadEventRaw
s.
#[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: Gamepad
The gamepad this event corresponds to.
event_type: GamepadEventType
The type of the event.
Implementations
impl GamepadEventRaw
impl GamepadEventRaw
pub fn new(gamepad: Gamepad, event_type: GamepadEventType) -> GamepadEventRaw
pub fn new(gamepad: Gamepad, event_type: GamepadEventType) -> GamepadEventRaw
Creates a new GamepadEventRaw
.
Trait Implementations
impl Clone for GamepadEventRaw
impl Clone for GamepadEventRaw
fn clone(&self) -> GamepadEventRaw
fn clone(&self) -> GamepadEventRaw
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreimpl Debug for GamepadEventRaw
impl Debug for GamepadEventRaw
impl FromReflect for GamepadEventRawwhere
Gamepad: FromReflect,
GamepadEventType: FromReflect,
impl FromReflect for GamepadEventRawwhere
Gamepad: FromReflect,
GamepadEventType: FromReflect,
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.impl GetTypeRegistration for GamepadEventRaw
impl GetTypeRegistration for GamepadEventRaw
impl PartialEq<GamepadEventRaw> for GamepadEventRaw
impl PartialEq<GamepadEventRaw> for GamepadEventRaw
fn eq(&self, other: &GamepadEventRaw) -> bool
fn eq(&self, other: &GamepadEventRaw) -> bool
impl Reflect for GamepadEventRaw
impl Reflect for GamepadEventRaw
fn get_type_info(&self) -> &'static TypeInfo
fn get_type_info(&self) -> &'static TypeInfo
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>
.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
.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.
fn as_reflect(&self) -> &(dyn Reflect + 'static)
fn as_reflect(&self) -> &(dyn Reflect + 'static)
Casts this type to a reflected value.
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.
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 morefn 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
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
fn reflect_ref(&self) -> ReflectRef<'_>
fn reflect_ref(&self) -> ReflectRef<'_>
Returns an enumeration of “kinds” of type. Read more
fn reflect_mut(&mut self) -> ReflectMut<'_>
fn reflect_mut(&mut self) -> ReflectMut<'_>
Returns a mutable enumeration of “kinds” of type. Read more
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
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
fn reflect_hash(&self) -> Option<u64>
fn reflect_hash(&self) -> Option<u64>
Returns a hash of the value (which includes the type). Read more
fn serializable(&self) -> Option<Serializable<'_>>
fn serializable(&self) -> Option<Serializable<'_>>
Returns a serializable version of the value. Read more
impl Struct for GamepadEventRaw
impl Struct for GamepadEventRaw
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 morefn iter_fields(&self) -> FieldIter<'_>ⓘ
fn iter_fields(&self) -> FieldIter<'_>ⓘ
Returns an iterator over the values of the reflectable fields for this struct.
fn clone_dynamic(&self) -> DynamicStruct
fn clone_dynamic(&self) -> DynamicStruct
Clones the struct into a
DynamicStruct
.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, U> AsBindGroupShaderType<U> for Twhere
U: ShaderType,
&'a T: for<'a> Into<U>,
impl<T, U> AsBindGroupShaderType<U> for Twhere
U: ShaderType,
&'a T: for<'a> Into<U>,
fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
Return the
T
ShaderType
for self
. When used in AsBindGroup
derives, it is safe to assume that all images in self
exist. Read moresourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
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 morefn 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 morefn 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 morefn 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 moreimpl<S> GetField for Swhere
S: Struct,
impl<S> GetField for Swhere
S: Struct,
impl<T> GetPath for Twhere
T: Reflect,
impl<T> GetPath for Twhere
T: Reflect,
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 morefn 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 morefn 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
.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