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 <alice.i.cecile@gmail.com>
This commit is contained in:
		
							parent
							
								
									755917fe4b
								
							
						
					
					
						commit
						397d111ea7
					
				| @ -146,6 +146,15 @@ pub trait AppGizmoBuilder { | |||||||
|     ///
 |     ///
 | ||||||
|     /// Configurations can be set using the [`GizmoConfigStore`] [`Resource`].
 |     /// Configurations can be set using the [`GizmoConfigStore`] [`Resource`].
 | ||||||
|     fn init_gizmo_group<T: GizmoConfigGroup + Default>(&mut self) -> &mut Self; |     fn init_gizmo_group<T: GizmoConfigGroup + Default>(&mut self) -> &mut Self; | ||||||
|  | 
 | ||||||
|  |     /// Insert the [`GizmoConfigGroup`] in the app with the given value and [`GizmoConfig`].
 | ||||||
|  |     ///
 | ||||||
|  |     /// This method should be preferred over [`AppGizmoBuilder::init_gizmo_group`] if and only if you need to configure fields upon initialization.
 | ||||||
|  |     fn insert_gizmo_group<T: GizmoConfigGroup>( | ||||||
|  |         &mut self, | ||||||
|  |         group: T, | ||||||
|  |         config: GizmoConfig, | ||||||
|  |     ) -> &mut Self; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl AppGizmoBuilder for App { | impl AppGizmoBuilder for App { | ||||||
| @ -169,6 +178,31 @@ impl AppGizmoBuilder for App { | |||||||
| 
 | 
 | ||||||
|         self |         self | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     fn insert_gizmo_group<T: GizmoConfigGroup>( | ||||||
|  |         &mut self, | ||||||
|  |         group: T, | ||||||
|  |         config: GizmoConfig, | ||||||
|  |     ) -> &mut Self { | ||||||
|  |         if self.world.contains_resource::<GizmoStorage<T>>() { | ||||||
|  |             return self; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         self.init_resource::<GizmoStorage<T>>() | ||||||
|  |             .add_systems(Last, update_gizmo_meshes::<T>); | ||||||
|  | 
 | ||||||
|  |         self.world | ||||||
|  |             .get_resource_or_insert_with::<GizmoConfigStore>(Default::default) | ||||||
|  |             .insert(config, group); | ||||||
|  | 
 | ||||||
|  |         let Ok(render_app) = self.get_sub_app_mut(RenderApp) else { | ||||||
|  |             return self; | ||||||
|  |         }; | ||||||
|  | 
 | ||||||
|  |         render_app.add_systems(ExtractSchedule, extract_gizmo_data::<T>); | ||||||
|  | 
 | ||||||
|  |         self | ||||||
|  |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[derive(Resource, Default)] | #[derive(Resource, Default)] | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 pablo-lua
						pablo-lua