Skip to content

Commit 397d111

Browse files
Insert Gizmos config instead of Init (#11580)
# Objective - Fixes #11569 ## Solution - Add new methods to the Ext Trait --- ## Changelog ### Added - Added new methods to the trait `AppGizmoBuilder` --------- Co-authored-by: Alice Cecile <[email protected]>
1 parent 755917f commit 397d111

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

crates/bevy_gizmos/src/lib.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,15 @@ pub trait AppGizmoBuilder {
146146
///
147147
/// Configurations can be set using the [`GizmoConfigStore`] [`Resource`].
148148
fn init_gizmo_group<T: GizmoConfigGroup + Default>(&mut self) -> &mut Self;
149+
150+
/// Insert the [`GizmoConfigGroup`] in the app with the given value and [`GizmoConfig`].
151+
///
152+
/// This method should be preferred over [`AppGizmoBuilder::init_gizmo_group`] if and only if you need to configure fields upon initialization.
153+
fn insert_gizmo_group<T: GizmoConfigGroup>(
154+
&mut self,
155+
group: T,
156+
config: GizmoConfig,
157+
) -> &mut Self;
149158
}
150159

151160
impl AppGizmoBuilder for App {
@@ -169,6 +178,31 @@ impl AppGizmoBuilder for App {
169178

170179
self
171180
}
181+
182+
fn insert_gizmo_group<T: GizmoConfigGroup>(
183+
&mut self,
184+
group: T,
185+
config: GizmoConfig,
186+
) -> &mut Self {
187+
if self.world.contains_resource::<GizmoStorage<T>>() {
188+
return self;
189+
}
190+
191+
self.init_resource::<GizmoStorage<T>>()
192+
.add_systems(Last, update_gizmo_meshes::<T>);
193+
194+
self.world
195+
.get_resource_or_insert_with::<GizmoConfigStore>(Default::default)
196+
.insert(config, group);
197+
198+
let Ok(render_app) = self.get_sub_app_mut(RenderApp) else {
199+
return self;
200+
};
201+
202+
render_app.add_systems(ExtractSchedule, extract_gizmo_data::<T>);
203+
204+
self
205+
}
172206
}
173207

174208
#[derive(Resource, Default)]

0 commit comments

Comments
 (0)