Skip to content

Send events via a channels form anywhere (eg. web-dom, c-ffi) to Bevy Observers

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_trigger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.14 0.1

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. web-dom, c-ffi) to Bevy Observers

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Sponsor this project