Giter Club home page Giter Club logo

bevy_crossbeam_event's Introduction

bevy_crossbeam_event

crates.io MIT/Apache 2.0 crates.io docs.rs

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.

Usage

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

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

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

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

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:?}");
    }
}

Bevy Version Support

The main branch targets the latest bevy release.

bevy bevy_crossbeam_event
0.13 0.5, main
0.12 0.3
0.11 0.2
0.10 0.1

License

bevy_crossbeam_event is dual-licensed under either

at your option.

Contributions

PRs welcome!

bevy_crossbeam_event's People

Contributors

johanhelsing avatar sjmueller avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.