-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcustom_osc_method.rs
45 lines (36 loc) · 1.3 KB
/
custom_osc_method.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
44
45
//! Add a custom component implementing OscMethod and have it receive messages
extern crate bevy_rosc;
use bevy::prelude::*;
use rosc::address::OscAddress;
use rosc::OscMessage;
use bevy_rosc::{BevyRoscPlugin, method_dispatcher_system};
use bevy_rosc::OscMethod;
#[derive(Component)]
struct MyOscMethod {
osc_address: OscAddress,
}
impl OscMethod for MyOscMethod {
fn get_addresses(&self) -> Vec<OscAddress> {
return vec![self.osc_address.clone()];
}
// This method is called when an OSC message was successfully matched with the method
fn receive_message(&mut self, osc_message: OscMessage) {
println!("MyOscMethod received: {:?}", osc_message)
}
}
fn startup(mut commands: Commands) {
println!("** Startup");
// Spawn entity with custom OSC receiving component
commands.spawn(MyOscMethod{osc_address: OscAddress::new("/test/address".into()).unwrap()});
}
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 dispatcher system for MyOscMethod
.add_systems(Update, method_dispatcher_system::<MyOscMethod>)
.add_systems(Startup, startup)
.run();
}