pub struct ActionBinding { /* private fields */ }Expand description
Bindings associated with an InputAction marker.
Stored inside Actions.
Bindings are stored separately from ActionMap to allow reading other actions’ data during evaluation.
Action bindings evaluation follows these steps:
- Iterate over each
ActionValuefrom the associatedInputs: 1.1. Apply input-levelInputModifiers. 1.2. Evaluate input-levelInputConditions, combining their results based on theirInputCondition::kind. - Select all
ActionValues with the most significantActionStateand combine based onInputAction::ACCUMULATION. Combined value will be converted intoInputAction::OutputusingActionValue::convert. - Apply action level
InputModifiers. - Evaluate action level
InputConditions, combining their results according toInputCondition::kind. - Set the final
ActionStatebased on the results. Final value will be converted intoInputAction::OutputusingActionValue::convert.
Implementations§
Source§impl ActionBinding
impl ActionBinding
Sourcepub fn inputs(&self) -> &[InputBinding]
pub fn inputs(&self) -> &[InputBinding]
Returns associated input bindings.
See also Self::to.
Sourcepub fn with_modifiers(&mut self, modifiers: impl IntoModifiers) -> &mut Self
pub fn with_modifiers(&mut self, modifiers: impl IntoModifiers) -> &mut Self
Adds action-level modifiers.
For input-level modifiers see
BindingBuilder::with_modifiers.
§Examples
Single modifier:
actions.bind::<Jump>()
.to(KeyCode::Space)
.with_modifiers(Scale::splat(2.0));Multiple modifiers:
actions.bind::<Jump>()
.to(KeyCode::Space)
.with_modifiers((Scale::splat(2.0), Negate::all()));Sourcepub fn with_conditions(&mut self, conditions: impl IntoConditions) -> &mut Self
pub fn with_conditions(&mut self, conditions: impl IntoConditions) -> &mut Self
Adds action-level conditions.
For input-level conditions see
BindingBuilder::with_conditions.
§Examples
Single condition:
actions.bind::<Jump>()
.to(KeyCode::Space)
.with_conditions(Release::default());Multiple conditions:
actions.bind::<Jump>()
.to(KeyCode::Space)
.with_conditions((Release::default(), JustPress::default()));Sourcepub fn to(&mut self, bindings: impl IntoBindings) -> &mut Self
pub fn to(&mut self, bindings: impl IntoBindings) -> &mut Self
Adds input mapping.
Thanks to traits, this function can be called with multiple types:
- Raw input types.
Inputenum which wraps any supported raw input and can store keyboard modifiers.InputBindingwhich wrapsInputand can store input modifiers or conditions.IntoBindingswhich wrapsInputBindingand can store multipleInputBindings. Also implemented on tuples, so you can pass multiple inputs to a single call.
All assigned inputs will be evaluated separately (equivalent to “any of”).
If you’re looking for a chord, see the Chord condition.
§Examples
Raw input:
actions.bind::<Jump>()
.to((KeyCode::Space, GamepadButton::South));Raw input with keyboard modifiers:
actions.bind::<Jump>().to(KeyCode::Space.with_mod_keys(ModKeys::CONTROL));Raw input with input conditions or modifiers:
actions.bind::<Jump>().to(KeyCode::Space.with_conditions(Release::default()));
actions.bind::<Attack>().to(MouseButton::Left.with_modifiers(Scale::splat(10.0)));Input type directly:
actions.bind::<Zoom>().to(Input::mouse_wheel());
actions.bind::<Move>().to(Input::mouse_motion());Convenience preset which consists of multiple inputs with predefined conditions and modifiers:
actions.bind::<Move>().to(Cardinal::wasd_keys());Multiple buttons from settings:
actions.bind::<Inspect>().to(&settings.inspect);
struct KeyboardSettings {
inspect: Vec<KeyCode>,
}Auto Trait Implementations§
impl Freeze for ActionBinding
impl !RefUnwindSafe for ActionBinding
impl Send for ActionBinding
impl Sync for ActionBinding
impl Unpin for ActionBinding
impl !UnwindSafe for ActionBinding
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more