From faa1387720889025bff86132ef9b343623ccb6df Mon Sep 17 00:00:00 2001 From: Sludge <96552222+SludgePhD@users.noreply.github.com> Date: Sun, 25 Feb 2024 02:57:44 +0100 Subject: [PATCH] Reflect `GizmoConfigStore` (#12104) # Objective - Make `GizmoConfigStore` play well with reflection-based workflows like editors. ## Solution - `#[derive(Reflect)]` and call `.register_type()`. --- crates/bevy_gizmos/src/config.rs | 8 +++++--- crates/bevy_gizmos/src/lib.rs | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/bevy_gizmos/src/config.rs b/crates/bevy_gizmos/src/config.rs index a8bf73b5c2..03675b168b 100644 --- a/crates/bevy_gizmos/src/config.rs +++ b/crates/bevy_gizmos/src/config.rs @@ -3,8 +3,8 @@ use crate as bevy_gizmos; pub use bevy_gizmos_macros::GizmoConfigGroup; -use bevy_ecs::{component::Component, system::Resource}; -use bevy_reflect::{Reflect, TypePath}; +use bevy_ecs::{component::Component, reflect::ReflectResource, system::Resource}; +use bevy_reflect::{std_traits::ReflectDefault, Reflect, TypePath}; use bevy_render::view::RenderLayers; use bevy_utils::TypeIdMap; use core::panic; @@ -27,9 +27,11 @@ pub struct DefaultGizmoConfigGroup; /// A [`Resource`] storing [`GizmoConfig`] and [`GizmoConfigGroup`] structs /// /// Use `app.init_gizmo_group::()` to register a custom config group. -#[derive(Resource, Default)] +#[derive(Reflect, Resource, Default)] +#[reflect(Resource, Default)] pub struct GizmoConfigStore { // INVARIANT: must map TypeId::of::() to correct type T + #[reflect(ignore)] store: TypeIdMap<(GizmoConfig, Box)>, } diff --git a/crates/bevy_gizmos/src/lib.rs b/crates/bevy_gizmos/src/lib.rs index fe6e16553a..705d193f25 100644 --- a/crates/bevy_gizmos/src/lib.rs +++ b/crates/bevy_gizmos/src/lib.rs @@ -98,6 +98,7 @@ impl Plugin for GizmoPlugin { load_internal_asset!(app, LINE_SHADER_HANDLE, "lines.wgsl", Shader::from_wgsl); app.register_type::() + .register_type::() .add_plugins(UniformComponentPlugin::::default()) .init_asset::() .add_plugins(RenderAssetPlugin::::default())