https://github.com/rustunit/bevy_channel_trigger
Send events via a channels form anywhere (eg. web-dom, c-ffi) to Bevy Observers
https://github.com/rustunit/bevy_channel_trigger
Last synced: 9 months ago
JSON representation
Send events via a channels form anywhere (eg. web-dom, c-ffi) to Bevy Observers
- Host: GitHub
- URL: https://github.com/rustunit/bevy_channel_trigger
- Owner: rustunit
- License: apache-2.0
- Created: 2024-08-30T11:39:29.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-30T23:07:48.000Z (about 1 year ago)
- Last Synced: 2024-12-10T11:53:48.041Z (about 1 year ago)
- Language: Rust
- Homepage:
- Size: 288 KB
- Stars: 18
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# bevy_channel_trigger
[](https://bevyengine.org/learn/quick-start/plugin-development/#main-branch-tracking)
[](https://crates.io/crates/bevy_channel_trigger)
[](https://docs.rs/bevy_channel_trigger)
Send events via a channel from anywhere (eg. web-dom, c-ffi) to Bevy Observers.
Inspired by [bevy_crossbeam_event](https://github.com/johanhelsing/bevy_crossbeam_event) but delivering the events via Bevy Observers instead of `EventReader`.

# example
```rust
#[derive(Event)]
struct MyEvent(i32);
fn main() {
use bevy_channel_trigger::ChannelTriggerApp;
let mut app = App::new();
app.add_plugins(MinimalPlugins);
// create channel
let sender = app.add_channel_trigger::();
// use sender from anywhere:
thread::spawn(move || {
let mut counter = 1;
loop {
// send events back to bevy
sender.send(MyEvent(counter));
thread::sleep(Duration::from_secs(1));
counter += 1;
}
});
// register an observer to receive the events sent via `sender`
app.observe(on_event);
app.run();
}
// regular bevy observer to handle these events coming into the bevy world
fn on_event(trigger: Trigger) {
let event = trigger.event();
println!("trigger with: {}", event.0);
}
```
# Other examples
* [bevy_web_drop_image_as_sprite](https://github.com/rustunit/bevy_web_drop_image_as_sprite)
## Our Other Crates
- [bevy_debug_log](https://github.com/rustunit/bevy_debug_log)
- [bevy_device_lang](https://github.com/rustunit/bevy_device_lang)
- [bevy_web_popups](https://github.com/rustunit/bevy_web_popups)
- [bevy_libgdx_atlas](https://github.com/rustunit/bevy_libgdx_atlas)
- [bevy_ios_iap](https://github.com/rustunit/bevy_ios_iap)
- [bevy_ios_review](https://github.com/rustunit/bevy_ios_review)
- [bevy_ios_gamecenter](https://github.com/rustunit/bevy_ios_gamecenter)
- [bevy_ios_alerts](https://github.com/rustunit/bevy_ios_alerts)
- [bevy_ios_notifications](https://github.com/rustunit/bevy_ios_notifications)
- [bevy_ios_impact](https://github.com/rustunit/bevy_ios_impact)
- [bevy_ios_safearea](https://github.com/rustunit/bevy_ios_safearea)
## Compatible Bevy Versions
|bevy|our version|
|-|-|
|0.16|0.4,main|
|0.15|0.3|
|0.14|0.1,0.2|
## License
this crate is dual-licensed under either [MIT](https://opensource.org/license/MIT) or [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0), at your option.