mirror of
https://github.com/bevyengine/bevy
synced 2024-11-13 00:17:27 +00:00
Reflect GizmoConfigStore
(#12104)
# Objective - Make `GizmoConfigStore` play well with reflection-based workflows like editors. ## Solution - `#[derive(Reflect)]` and call `.register_type()`.
This commit is contained in:
parent
de004da8d5
commit
c0a52d97e1
2 changed files with 6 additions and 3 deletions
|
@ -3,8 +3,8 @@
|
||||||
use crate as bevy_gizmos;
|
use crate as bevy_gizmos;
|
||||||
pub use bevy_gizmos_macros::GizmoConfigGroup;
|
pub use bevy_gizmos_macros::GizmoConfigGroup;
|
||||||
|
|
||||||
use bevy_ecs::{component::Component, system::Resource};
|
use bevy_ecs::{component::Component, reflect::ReflectResource, system::Resource};
|
||||||
use bevy_reflect::{Reflect, TypePath};
|
use bevy_reflect::{std_traits::ReflectDefault, Reflect, TypePath};
|
||||||
use bevy_render::view::RenderLayers;
|
use bevy_render::view::RenderLayers;
|
||||||
use bevy_utils::TypeIdMap;
|
use bevy_utils::TypeIdMap;
|
||||||
use core::panic;
|
use core::panic;
|
||||||
|
@ -27,9 +27,11 @@ pub struct DefaultGizmoConfigGroup;
|
||||||
/// A [`Resource`] storing [`GizmoConfig`] and [`GizmoConfigGroup`] structs
|
/// A [`Resource`] storing [`GizmoConfig`] and [`GizmoConfigGroup`] structs
|
||||||
///
|
///
|
||||||
/// Use `app.init_gizmo_group::<T>()` to register a custom config group.
|
/// Use `app.init_gizmo_group::<T>()` to register a custom config group.
|
||||||
#[derive(Resource, Default)]
|
#[derive(Reflect, Resource, Default)]
|
||||||
|
#[reflect(Resource, Default)]
|
||||||
pub struct GizmoConfigStore {
|
pub struct GizmoConfigStore {
|
||||||
// INVARIANT: must map TypeId::of::<T>() to correct type T
|
// INVARIANT: must map TypeId::of::<T>() to correct type T
|
||||||
|
#[reflect(ignore)]
|
||||||
store: TypeIdMap<(GizmoConfig, Box<dyn Reflect>)>,
|
store: TypeIdMap<(GizmoConfig, Box<dyn Reflect>)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,6 +98,7 @@ impl Plugin for GizmoPlugin {
|
||||||
load_internal_asset!(app, LINE_SHADER_HANDLE, "lines.wgsl", Shader::from_wgsl);
|
load_internal_asset!(app, LINE_SHADER_HANDLE, "lines.wgsl", Shader::from_wgsl);
|
||||||
|
|
||||||
app.register_type::<GizmoConfig>()
|
app.register_type::<GizmoConfig>()
|
||||||
|
.register_type::<GizmoConfigStore>()
|
||||||
.add_plugins(UniformComponentPlugin::<LineGizmoUniform>::default())
|
.add_plugins(UniformComponentPlugin::<LineGizmoUniform>::default())
|
||||||
.init_asset::<LineGizmo>()
|
.init_asset::<LineGizmo>()
|
||||||
.add_plugins(RenderAssetPlugin::<LineGizmo>::default())
|
.add_plugins(RenderAssetPlugin::<LineGizmo>::default())
|
||||||
|
|
Loading…
Reference in a new issue