impl Reflect + Clone for StateScoped (#14156)
# Objective - Expand the flexibilty of StateScoped by adding Reflect and Clone - This lets StateScoped be used in Clone Bundles, for example ```rust #[derive(Component, Reflect, Clone)] pub struct StateScoped<S: States>(pub S); ``` Notes: - States are already Clone. - Type registration is up to the user, but this is commonly the case with reflected generic types. ## Testing - Ran the examples.
This commit is contained in:
parent
7273ffcd78
commit
02028d16b3
@ -1,3 +1,5 @@
|
|||||||
|
#[cfg(feature = "bevy_reflect")]
|
||||||
|
use bevy_ecs::reflect::ReflectComponent;
|
||||||
use bevy_ecs::{
|
use bevy_ecs::{
|
||||||
component::Component,
|
component::Component,
|
||||||
entity::Entity,
|
entity::Entity,
|
||||||
@ -6,6 +8,8 @@ use bevy_ecs::{
|
|||||||
};
|
};
|
||||||
#[cfg(feature = "bevy_hierarchy")]
|
#[cfg(feature = "bevy_hierarchy")]
|
||||||
use bevy_hierarchy::DespawnRecursiveExt;
|
use bevy_hierarchy::DespawnRecursiveExt;
|
||||||
|
#[cfg(feature = "bevy_reflect")]
|
||||||
|
use bevy_reflect::prelude::*;
|
||||||
|
|
||||||
use crate::state::{StateTransitionEvent, States};
|
use crate::state::{StateTransitionEvent, States};
|
||||||
|
|
||||||
@ -52,7 +56,8 @@ use crate::state::{StateTransitionEvent, States};
|
|||||||
/// app.enable_state_scoped_entities::<GameState>();
|
/// app.enable_state_scoped_entities::<GameState>();
|
||||||
/// app.add_systems(OnEnter(GameState::InGame), spawn_player);
|
/// app.add_systems(OnEnter(GameState::InGame), spawn_player);
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Component)]
|
#[derive(Component, Clone)]
|
||||||
|
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Component))]
|
||||||
pub struct StateScoped<S: States>(pub S);
|
pub struct StateScoped<S: States>(pub S);
|
||||||
|
|
||||||
/// Removes entities marked with [`StateScoped<S>`]
|
/// Removes entities marked with [`StateScoped<S>`]
|
||||||
|
Loading…
Reference in New Issue
Block a user