add centeral actionset syncing

Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
Schmarni
2024-05-15 22:33:00 +02:00
parent d26e6b7acf
commit 764da56d50
3 changed files with 39 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
use crate::{init::OxrPreUpdateSet, resources::OxrSession};
use bevy::prelude::*;
use bevy_xr::session::{session_running, status_changed_to};
impl Plugin for OxrActionSyncingPlugin {
fn build(&self, app: &mut App) {
app.add_event::<OxrAttachActionSet>();
app.add_systems(
PreUpdate,
sync_sets
.run_if(session_running)
.in_set(OxrPreUpdateSet::SyncActions),
);
}
}
fn sync_sets(session: Res<OxrSession>, mut events: EventReader<OxrSyncActionSet>) {
let sets = events
.read()
.map(|v| &v.0)
.map(|s| openxr::ActionSet::from(s))
.collect::<Vec<_>>();
if sets.is_empty() {
return;
}
if let Err(err) = session.sync_actions(sets) {
warn!("error while syncing actionsets: {}", err.to_string());
}
}
#[derive(Event, Clone)]
/// Send this event for every ActionSet you want to attach to the [`OxrSession`] once the Session Status changed to Ready. all requests will
pub struct OxrSyncActionSet(pub openxr::ActionSet);
pub struct OxrActionSyncingPlugin;