blob: 7c3de07a90910fc4f1f7799f1255376a46c4eec5 (
plain)
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
|
# bevy_basic_interaction
![License](https://img.shields.io/badge/license-0BSD%2FMIT%2FApache-blue.svg)
![Tag](https://img.shields.io/github/v/tag/exvacuum/bevy_basic_interaction)
![Build](https://img.shields.io/github/actions/workflow/status/exvacuum/bevy_basic_interaction/rust.yml)
This crate provides an `InteractionPlugin` which enables a basic interaction system.
This plugin is mostly for my own internal use, but feel free to use it or contribute if you feel like it.
## Compatibility
| Crate Version | Bevy Version |
|--- |--- |
| 0.1 | 0.14 |
## Installation
If enough people (like literally 1 person) want this on crates.io I'll consider putting it up there, but for now just add the GitHub URL to your `Cargo.toml`:
```toml
[dependencies.bevy_basic_interaction]
git = "https://github.com/exvacuum/bevy_basic_interaction"
```
## Usage
This plugin works based on a system of `Interactor`s and `Interactable`s. `Interactor`s maintain a list of "target" `Interactable`s which are in range of the interactor (based on a maximum distance defined in the *interactable*). The user can invoke an `InteractorFiredEvent`, passing the `Entity` with an `Interactor` component on it, and the plugin will automatically determine which interactables to invoke a corresponding `InteractionEvent` for.
In main function:
```rs
use bevy::prelude::*;
use bevy_basic_interaction::InteractionPlugin;
fn main() {
App::new()
// ...
.add_plugins(InteractionPlugin)
// ...
.run();
}
```
Raising an interactor event (`entity` must be an entity with both an `Interactor` and a `GlobalTransform` component):
```rs
// ...
event_writer.send(InteractorFiredEvent(entity));
// ...
```
Handling an interaction event:
```rs
// ...
for InteractionEvent { interactable, .. } in event_reader.read() {
let interactable = interactable_query.get(interactable).unwrap();
// Do something with interactable here...
}
// ...
```
## License
This crate is licensed under your choice of 0BSD, Apache-2.0, or MIT license.
|