Fire Bevy events from crossbeam channels.
Useful if you need to handle callbacks in 3rd party libraries etc. like
steamworks-rs
, or getting events out of tracing
layers.
Add add events to your app using .add_crossbeam_event::<EventType>
:
```rust ignore
struct LobbyJoined(Lobby);
impl Plugin for MyPlugin {
fn build(&self, app: &mut App) {
app.addcrossbeamevent::
Fire events by using Res<CrossbeamEventSender<EventType>>
(which can be
cloned and sent into callbacks):
rust ignore
fn setup(service: Res<ThirdPartyCode>, sender: Res<CrossbeamEventSender<LobbyJoined>>) {
let sender = sender.clone();
service.join_lobby(id, move |lobby| {
sender.send(LobbyJoined(lobby));
});
}
Handle the events just like normal Bevy events (which they are):
fn handle_lobby_joined(mut lobby_joined_events: EventReader<LobbyJoined>) {
for lobby in lobby_joined_events.iter() {
info!("lobby joined: {lobby:?}");
}
}
The main
branch targets the latest bevy release.
|bevy|bevycrossbeamevent| |----|--------------------| |0.10|0.1, main |
bevy_crossbeam_event
is dual-licensed under either
at your option.
PRs welcome!