add resource to disable auto session creation and change autocreation to disable itself after the each autocreation
Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
@@ -6,6 +6,7 @@ pub struct XrSessionPlugin;
|
|||||||
|
|
||||||
impl Plugin for XrSessionPlugin {
|
impl Plugin for XrSessionPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
|
app.init_resource::<XrCreateSessionWhenAvailabe>();
|
||||||
app.init_schedule(XrSessionCreated);
|
app.init_schedule(XrSessionCreated);
|
||||||
app.init_schedule(XrSessionExiting);
|
app.init_schedule(XrSessionExiting);
|
||||||
app.add_event::<CreateXrSession>()
|
app.add_event::<CreateXrSession>()
|
||||||
@@ -13,10 +14,10 @@ impl Plugin for XrSessionPlugin {
|
|||||||
.add_event::<BeginXrSession>()
|
.add_event::<BeginXrSession>()
|
||||||
.add_event::<EndXrSession>()
|
.add_event::<EndXrSession>()
|
||||||
.add_event::<XrStatusChanged>()
|
.add_event::<XrStatusChanged>()
|
||||||
// .add_systems(
|
.add_systems(
|
||||||
// PreUpdate,
|
PreUpdate,
|
||||||
// handle_session.run_if(resource_exists::<XrSharedStatus>),
|
handle_session.run_if(resource_exists::<XrSharedStatus>),
|
||||||
/* ) */;
|
);
|
||||||
}
|
}
|
||||||
fn finish(&self, app: &mut App) {
|
fn finish(&self, app: &mut App) {
|
||||||
// This is in finnish because we need the RenderPlugin to already be added.
|
// This is in finnish because we need the RenderPlugin to already be added.
|
||||||
@@ -26,6 +27,17 @@ impl Plugin for XrSessionPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Automatically starts session when it's available, gets set to false after the start event was
|
||||||
|
/// sent
|
||||||
|
#[derive(Clone, Copy, Resource, Deref, DerefMut)]
|
||||||
|
pub struct XrCreateSessionWhenAvailabe(pub bool);
|
||||||
|
|
||||||
|
impl Default for XrCreateSessionWhenAvailabe {
|
||||||
|
fn default() -> Self {
|
||||||
|
XrCreateSessionWhenAvailabe(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(ScheduleLabel, Clone, Copy, PartialEq, Eq, Debug, Hash)]
|
#[derive(ScheduleLabel, Clone, Copy, PartialEq, Eq, Debug, Hash)]
|
||||||
pub struct XrSessionCreated;
|
pub struct XrSessionCreated;
|
||||||
|
|
||||||
@@ -79,15 +91,19 @@ pub fn handle_session(
|
|||||||
mut previous_status: Local<Option<XrStatus>>,
|
mut previous_status: Local<Option<XrStatus>>,
|
||||||
mut create_session: EventWriter<CreateXrSession>,
|
mut create_session: EventWriter<CreateXrSession>,
|
||||||
mut begin_session: EventWriter<BeginXrSession>,
|
mut begin_session: EventWriter<BeginXrSession>,
|
||||||
mut end_session: EventWriter<EndXrSession>,
|
// mut end_session: EventWriter<EndXrSession>,
|
||||||
mut destroy_session: EventWriter<DestroyXrSession>,
|
mut destroy_session: EventWriter<DestroyXrSession>,
|
||||||
|
mut should_start_session: ResMut<XrCreateSessionWhenAvailabe>,
|
||||||
) {
|
) {
|
||||||
let current_status = status.get();
|
let current_status = status.get();
|
||||||
if *previous_status != Some(current_status) {
|
if *previous_status != Some(current_status) {
|
||||||
match current_status {
|
match current_status {
|
||||||
XrStatus::Unavailable => {}
|
XrStatus::Unavailable => {}
|
||||||
XrStatus::Available => {
|
XrStatus::Available => {
|
||||||
|
if **should_start_session {
|
||||||
create_session.send_default();
|
create_session.send_default();
|
||||||
|
**should_start_session = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
XrStatus::Idle => {}
|
XrStatus::Idle => {}
|
||||||
XrStatus::Ready => {
|
XrStatus::Ready => {
|
||||||
|
|||||||
Reference in New Issue
Block a user