pub trait Actionlike: Send + Sync + Clone + 'static {
    const N_VARIANTS: usize;

    fn get_at(index: usize) -> Option<Self>;
    fn index(&self) -> usize;

    fn variants() -> ActionIter<Self>Notable traits for ActionIter<A>impl<A: Actionlike> Iterator for ActionIter<A>    type Item = A; { ... }
}
Expand description

Allows a type to be used as a gameplay action in an input-agnostic fashion

Actions are modelled as “virtual buttons”, 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.

Example

use leafwing_input_manager::Actionlike;

#[derive(Actionlike, PartialEq, Eq, Clone, Copy, Hash)]
enum PlayerAction {
   // Movement
   Up,
   Down,
   Left,
   Right,
   // Abilities
   Ability1,
   Ability2,
   Ability3,
   Ability4,
   Ultimate,
}

Required Associated Constants

The number of variants of this action type

Required Methods

Returns the default value for the action stored at the provided index if it exists

This is mostly used internally, to enable space-efficient iteration.

Returns the position in the defining enum of the given action

Provided Methods

Iterates over the possible actions in the order they were defined

Implementors