Skip to content

Send events via a channels form anywhere (eg. c-ffi) to Bevy (buffered) messages.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

rustunit/bevy_channel_message

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bevy_channel_message

Following released Bevy versions crates.io docs.rs

Send events via a channel from anywhere (eg. web-dom, c-ffi) to Bevy Observers. Based on the original bevy_crossbeam_event but reverting to the buffered message system instead of migrating to observer/triggers as it did in 0.9.

usage

Add add events to your app using .add_channel_message::<EventType>:

#[derive(Message, Clone, Debug)]
struct LobbyJoined(Lobby);

impl Plugin for MyPlugin {
    fn build(&self, app: &mut App) {
        app.add_channel_message::<LobbyJoined>();
        app.add_startup_system(setup);
        app.add_system(handle_lobby_joined);
    }
}

Fire events by using Res<ChannelMessageSender<EventType>> (which can be cloned and sent into callbacks):

fn setup(service: Res<ThirdPartyCode>, sender: Res<ChannelMessageSender<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: MessageReader<LobbyJoined>) {
    for lobby in lobby_joined_events.read() {
        info!("lobby joined: {lobby:?}");
    }
}

Our Other Crates

Compatible Bevy Versions

bevy our version
0.17 0.1,main

License

this crate is dual-licensed under either MIT or Apache 2.0, at your option.

About

Send events via a channels form anywhere (eg. c-ffi) to Bevy (buffered) messages.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages