pub trait Actionlike: Send + Sync + Clone + TypePath + 'static {
    // Required methods
    fn n_variants() -> usize;
    fn get_at(index: usize) -> Option<Self>;
    fn index(&self) -> usize;

    // Provided method
    fn variants() -> ActionIter<Self>  { ... }
}
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 bevy::prelude::Reflect;
use leafwing_input_manager::Actionlike;

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

Required Methods§

source

fn n_variants() -> usize

The number of variants of this action type

source

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

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.

source

fn index(&self) -> usize

Returns the position in the defining enum of the given action

Provided Methods§

source

fn variants() -> ActionIter<Self>

Iterates over the possible actions in the order they were defined

Implementors§