bevy_channel_trigger

Crates.iobevy_channel_trigger
lib.rsbevy_channel_trigger
version0.3.0
sourcesrc
created_at2024-11-03 17:14:15.182328
updated_at2024-11-30 23:08:20.404481
descriptionSend events via a channels form anywhere (eg. c-ffi) to Bevy Observers
homepage
repositoryhttps://github.com/rustunit/bevy_channel_trigger
max_upload_size
id1433989
size339,077
(extrawurst)

documentation

README

bevy_channel_trigger

Following released Bevy versions crates.io docs.rs

Send events via a channel from anywhere (eg. web-dom, c-ffi) to Bevy Observers. Inspired by bevy_crossbeam_event but delivering the events via Bevy Observers instead of EventReader.

schema

example

#[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::<MyEvent>();

    // 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<MyEvent>) {
    let event = trigger.event();
    println!("trigger with: {}", event.0);
}

Other examples

Our Other Crates

Compatible Bevy Versions

bevy our version
0.15 0.3,main
0.14 0.1,0.2

License

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

Commit count: 8

cargo fmt