-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplugin.rs
43 lines (36 loc) · 1.3 KB
/
plugin.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//! Default plugin example
extern crate bevy_rosc;
use bevy::prelude::*;
use bevy_rosc::OscMethod;
use bevy_rosc::{BevyRoscPlugin, SingleAddressOscMethod};
/// Startup system that just spawns some entity bundles
fn startup(mut commands: Commands) {
println!("** Startup");
// Spawn entity with OSC receiving component that has a single address
commands.spawn(SingleAddressOscMethod::new("/test/address".into()).unwrap());
}
/// System that listens for any `SingleAddressOscMethod` that has changed and then prints out the oldest received OscMessage
fn print_received_osc_packets(
mut query: Query<&mut SingleAddressOscMethod, Changed<SingleAddressOscMethod>>,
) {
for mut osc_receiver in query.iter_mut() {
let new_msg = osc_receiver.get_message();
if let Some(msg) = new_msg {
println!(
"Method {:?} received: {:?}",
osc_receiver.get_addresses(),
msg
)
}
}
}
fn main() {
App::new()
// Minimal Bevy plugins
.add_plugins(MinimalPlugins)
// Add the bevy_rosc plugin and have it listen on port 31337
.add_plugins(BevyRoscPlugin::new("0.0.0.0:31337").unwrap())
.add_systems(Startup, startup)
.add_systems(Update, print_received_osc_packets)
.run();
}