pub trait Actionlike:
Debug
+ Eq
+ Hash
+ Send
+ Sync
+ Clone
+ Reflect
+ TypePath
+ FromReflect
+ 'static {
// Required method
fn input_control_kind(&self) -> InputControlKind;
}
Expand description
Allows a type to be used as a gameplay action in an input-agnostic fashion
Actions are modelled as “virtual buttons” (or axes), cleanly abstracting over messy, customizable inputs in a way that can be easily consumed by your game logic.
This trait should be implemented on the A
type that you want to pass into InputManagerPlugin
.
Generally, these types will be very small (often data-less) enums.
As a result, the APIs in this crate accept actions by value, rather than reference.
While Copy
is not a required trait bound,
users are strongly encouraged to derive Copy
on these enums whenever possible to improve ergonomics.
§Examples
use bevy::prelude::Reflect;
use leafwing_input_manager::Actionlike;
#[derive(Actionlike, Debug, PartialEq, Eq, Clone, Copy, Hash, Reflect)]
enum PlayerAction {
// Movement
Up,
Down,
Left,
Right,
// Abilities
Ability1,
Ability2,
Ability3,
Ability4,
Ultimate,
}
§Customizing variant behavior
By default, the derive macro for this trait assumes that all actions are buttonlike.
You can customize this behavior by using the #[actionlike]
attribute,
either on the entire enum or on individual variants.
See the document of InputControlKind
for available options.
use bevy::prelude::*;
use leafwing_input_manager::prelude::*;
#[derive(Actionlike, Debug, PartialEq, Eq, Clone, Copy, Hash, Reflect)]
#[actionlike(Axis)] // This attribute applies to all variants in the enum
enum CameraAction {
Zoom, // This action is controlled by axes
#[actionlike(DualAxis)]
Move, // This action is controlled by dual axes since we have overridden the default option
#[actionlike(Button)]
TakePhoto, // This action is controlled by buttons since we have overridden the default option
}
Required Methods§
sourcefn input_control_kind(&self) -> InputControlKind
fn input_control_kind(&self) -> InputControlKind
Returns the kind of input control this action represents: buttonlike, axislike, or dual-axislike.