Add some missing reflect attributes (#14259)
# Objective - Some types are missing reflection attributes, which means we can't use them in scene serialization etc. - Effected types - `BorderRadius` - `AnimationTransitions` - `OnAdd` - `OnInsert` - `OnRemove` - My use-case for `OnAdd` etc to derive reflect is 'Serializable Observer Components'. Add the component, save the scene, then the observer is re-added on scene load. ```rust #[derive(Reflect)] struct MySerializeableObserver<T: Event>(#[reflect(ignore)]PhantomData<T>); impl<T: Event> Component for MySerializeableObserver<T> { const STORAGE_TYPE: StorageType = StorageType::Table; fn register_component_hooks(hooks: &mut ComponentHooks) { hooks.on_add(|mut world, entity, _| { world .commands() .entity(entity) .observe(|_trigger: Trigger<T>| { println!("it triggered etc."); }); }); } } ``` ## Solution - Add the missing traits ---
This commit is contained in:
parent
df3fcbd116
commit
6882420c7f
@ -5,9 +5,10 @@
|
|||||||
|
|
||||||
use bevy_ecs::{
|
use bevy_ecs::{
|
||||||
component::Component,
|
component::Component,
|
||||||
|
reflect::ReflectComponent,
|
||||||
system::{Query, Res},
|
system::{Query, Res},
|
||||||
};
|
};
|
||||||
use bevy_reflect::Reflect;
|
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
|
||||||
use bevy_time::Time;
|
use bevy_time::Time;
|
||||||
use bevy_utils::Duration;
|
use bevy_utils::Duration;
|
||||||
|
|
||||||
@ -28,6 +29,7 @@ use crate::{graph::AnimationNodeIndex, ActiveAnimation, AnimationPlayer};
|
|||||||
/// component to get confused about which animation is the "main" animation, and
|
/// component to get confused about which animation is the "main" animation, and
|
||||||
/// transitions will usually be incorrect as a result.
|
/// transitions will usually be incorrect as a result.
|
||||||
#[derive(Component, Default, Reflect)]
|
#[derive(Component, Default, Reflect)]
|
||||||
|
#[reflect(Component, Default)]
|
||||||
pub struct AnimationTransitions {
|
pub struct AnimationTransitions {
|
||||||
main_animation: Option<AnimationNodeIndex>,
|
main_animation: Option<AnimationNodeIndex>,
|
||||||
transitions: Vec<AnimationTransition>,
|
transitions: Vec<AnimationTransition>,
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::{self as bevy_ecs};
|
use crate::{self as bevy_ecs};
|
||||||
|
#[cfg(feature = "bevy_reflect")]
|
||||||
|
use bevy_reflect::Reflect;
|
||||||
/// Internal components used by bevy with a fixed component id.
|
/// Internal components used by bevy with a fixed component id.
|
||||||
/// Constants are used to skip [`TypeId`] lookups in hot paths.
|
/// Constants are used to skip [`TypeId`] lookups in hot paths.
|
||||||
|
|
||||||
@ -12,12 +14,15 @@ pub const ON_REMOVE: ComponentId = ComponentId::new(2);
|
|||||||
|
|
||||||
/// Trigger emitted when a component is added to an entity.
|
/// Trigger emitted when a component is added to an entity.
|
||||||
#[derive(Event)]
|
#[derive(Event)]
|
||||||
|
#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
|
||||||
pub struct OnAdd;
|
pub struct OnAdd;
|
||||||
|
|
||||||
/// Trigger emitted when a component is inserted on to to an entity.
|
/// Trigger emitted when a component is inserted on to to an entity.
|
||||||
#[derive(Event)]
|
#[derive(Event)]
|
||||||
|
#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
|
||||||
pub struct OnInsert;
|
pub struct OnInsert;
|
||||||
|
|
||||||
/// Trigger emitted when a component is removed from an entity.
|
/// Trigger emitted when a component is removed from an entity.
|
||||||
#[derive(Event)]
|
#[derive(Event)]
|
||||||
|
#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
|
||||||
pub struct OnRemove;
|
pub struct OnRemove;
|
||||||
|
@ -1988,7 +1988,7 @@ impl Default for ZIndex {
|
|||||||
///
|
///
|
||||||
/// <https://developer.mozilla.org/en-US/docs/Web/CSS/border-radius>
|
/// <https://developer.mozilla.org/en-US/docs/Web/CSS/border-radius>
|
||||||
#[derive(Component, Copy, Clone, Debug, PartialEq, Reflect)]
|
#[derive(Component, Copy, Clone, Debug, PartialEq, Reflect)]
|
||||||
#[reflect(PartialEq, Default)]
|
#[reflect(Component, PartialEq, Default)]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serialize",
|
feature = "serialize",
|
||||||
derive(serde::Serialize, serde::Deserialize),
|
derive(serde::Serialize, serde::Deserialize),
|
||||||
|
Loading…
Reference in New Issue
Block a user