Merge branch 'webxr-refactor' into example_actions
This commit is contained in:
37
crates/bevy_openxr/src/openxr/action_set_syncing.rs
Normal file
37
crates/bevy_openxr/src/openxr/action_set_syncing.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
use crate::{init::OxrPreUpdateSet, resources::OxrSession};
|
||||
use bevy::prelude::*;
|
||||
use bevy_xr::session::session_running;
|
||||
|
||||
impl Plugin for OxrActionSyncingPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_event::<OxrSyncActionSet>();
|
||||
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(openxr::ActiveActionSet::new)
|
||||
.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;
|
||||
@@ -42,6 +42,7 @@ pub enum OxrPreUpdateSet {
|
||||
HandleEvents,
|
||||
UpdateCriticalComponents,
|
||||
UpdateNonCriticalComponents,
|
||||
SyncActions,
|
||||
}
|
||||
|
||||
pub struct OxrInitPlugin {
|
||||
|
||||
@@ -28,6 +28,7 @@ pub mod reference_space;
|
||||
pub mod render;
|
||||
pub mod resources;
|
||||
pub mod types;
|
||||
pub mod action_set_syncing;
|
||||
|
||||
pub fn add_xr_plugins<G: PluginGroup>(plugins: G) -> PluginGroupBuilder {
|
||||
plugins
|
||||
@@ -43,6 +44,7 @@ pub fn add_xr_plugins<G: PluginGroup>(plugins: G) -> PluginGroupBuilder {
|
||||
.add(XrCameraPlugin)
|
||||
.add(action_set_attaching::OxrActionAttachingPlugin)
|
||||
.add(action_binding::OxrActionBindingPlugin)
|
||||
.add(action_set_syncing::OxrActionSyncingPlugin)
|
||||
// .add(XrActionPlugin)
|
||||
.set(WindowPlugin {
|
||||
primary_window: Some(Window {
|
||||
|
||||
Reference in New Issue
Block a user