1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*!
Instead of hardcoded states like "pressed" or "released", all actions use an abstract [`TriggerState`] component
(which is a required component of [`Action<C>`]). Its meaning depends on the assigned [input conditions](crate::condition),
which determine when the action is triggered. This allows you to define flexible behaviors, such as "hold for 1 second".
Input conditions are components that implement [`InputCondition`] trait. Similar to modifiers, you can attach them to
both actions and bindings. They also evaluated during [`EnhancedInputSystems::Update`] right after modifiers in their insertion
order and update [`TriggerState`] on the associated action entity.
If no conditions are attached, the action behaves like with [`Down`] condition with a zero actuation threshold,
meaning it will trigger on any non-zero input value.
# Examples
```
use bevy::{asset::AssetPlugin, prelude::*, scene::ScenePlugin};
use bevy_enhanced_input::prelude::*;
#[derive(Component, Default, Clone)]
struct Player;
#[derive(InputAction)]
#[action_output(bool)]
struct Jump;
#[derive(InputAction)]
#[action_output(bool)]
struct Fire;
# let mut app = App::new();
# app.add_plugins((MinimalPlugins, AssetPlugin::default(), ScenePlugin));
let world = app.world_mut();
world.spawn_scene(bsn! {
Player
Actions<Player> [
Action::<Jump>::new()
// The action will trigger only if held for 1 second.
~Hold::new(1.0)
Bindings [
Binding(KeyCode::Space)
--
Binding(GamepadButton::South)
]
--
Action::<Fire>::new()
// The action will trigger every 0.5 seconds while held.
~Pulse::new(0.5)
Bindings [
Binding(GamepadButton::RightTrigger2)
// Additionally the right trigger only counts if its value is greater than 0.3.
Down::new(0.3)
--
Binding(MouseButton::Left)
]
]
}).unwrap();
```
*/
use Debug;
use crate*;
/// Default actuation threshold for all conditions.
pub const DEFAULT_ACTUATION: f32 = 0.5;
/// Defines how input activates.
///
/// Conditions analyze the input, checking for minimum actuation values
/// and validating patterns like short taps, prolonged holds, or the typical "press"
/// or "release" events.
///
/// Can be attached both to bindings and actions.
///
/// If you create a custom condition, it needs to be registered using
/// [`InputConditionAppExt::add_input_condition`].
/// Determines how a condition contributes to the final [`TriggerState`].
///
/// If no conditions are provided, the state will be set to [`TriggerState::Fired`]
/// on any non-zero value, functioning similarly to a [`Down`] condition
/// with a zero actuation threshold.
///
/// For details about how actions are combined, see [`Actions`].