From b04db12c37b6b017b375854749e555b70d36445f Mon Sep 17 00:00:00 2001 From: andriyDev Date: Sat, 25 May 2024 01:50:07 -0700 Subject: [PATCH] Add a feature flag for using bevy_gltf_blueprints. --- crates/bevy_gltf_component_refs/Cargo.toml | 1 + crates/bevy_gltf_component_refs/src/lib.rs | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/crates/bevy_gltf_component_refs/Cargo.toml b/crates/bevy_gltf_component_refs/Cargo.toml index 9eb7718..a507053 100644 --- a/crates/bevy_gltf_component_refs/Cargo.toml +++ b/crates/bevy_gltf_component_refs/Cargo.toml @@ -19,6 +19,7 @@ bevy = { version = "0.13", default-features = false, features = [ "bevy_scene", ] } bevy_gltf_components = { version = "0.5", path = "../bevy_gltf_components" } +bevy_gltf_blueprints = { version = "0.10", path = "../bevy_gltf_blueprints", optional = true } [dev-dependencies] bevy = { version = "0.13", default-features = false, features = [ diff --git a/crates/bevy_gltf_component_refs/src/lib.rs b/crates/bevy_gltf_component_refs/src/lib.rs index 628111f..8df4a1e 100644 --- a/crates/bevy_gltf_component_refs/src/lib.rs +++ b/crates/bevy_gltf_component_refs/src/lib.rs @@ -4,7 +4,7 @@ use bevy::{ ecs::{ component::Component, entity::Entity, - query::With, + query::{Or, With}, reflect::ReflectComponent, schedule::{IntoSystemConfigs, IntoSystemSetConfigs, SystemSet}, system::{Commands, Query, Res, ResMut, Resource, SystemParam}, @@ -19,6 +19,9 @@ use bevy::{ use bevy_gltf_components::GltfComponentsSet; use std::marker::PhantomData; +#[cfg(feature = "bevy_gltf_blueprints")] +use bevy_gltf_blueprints::{BlueprintName, GltfBlueprintsSet}; + /// Plugin for keeping the GltfRefMap in sync. pub struct GltfRefMapPlugin; @@ -26,12 +29,16 @@ impl Plugin for GltfRefMapPlugin { fn build(&self, app: &mut App) { app.register_type::() .init_resource::() - .configure_sets( - Update, - (GltfRefsSet::CreateRefMap, GltfRefsSet::ResolveRefs) + .configure_sets(Update, { + let set = (GltfRefsSet::CreateRefMap, GltfRefsSet::ResolveRefs) .chain() - .after(GltfComponentsSet::Injection), - ) + .after(GltfComponentsSet::Injection); + + #[cfg(feature = "bevy_gltf_blueprints")] + let set = set.after(GltfBlueprintsSet::Spawn); + + set + }) .add_systems( Update, GltfRefMap::create_ref_map.in_set(GltfRefsSet::CreateRefMap), @@ -157,7 +164,10 @@ impl Default for GltfRefPlugin { /// SystemParam to find the Gltf that an entity belongs to. #[derive(SystemParam)] pub struct GltfForEntity<'w, 's> { + #[cfg(not(feature = "bevy_gltf_blueprints"))] gltfs: Query<'w, 's, (), With>>, + #[cfg(feature = "bevy_gltf_blueprints")] + gltfs: Query<'w, 's, (), Or<(With>, With)>>, hierarchy: Query<'w, 's, &'static Parent>, }