mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
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 changed files with 6 additions and 1 deletions
|
@ -1,3 +1,5 @@
|
|||
#[cfg(feature = "bevy_reflect")]
|
||||
use bevy_ecs::reflect::ReflectComponent;
|
||||
use bevy_ecs::{
|
||||
component::Component,
|
||||
entity::Entity,
|
||||
|
@ -6,6 +8,8 @@ use bevy_ecs::{
|
|||
};
|
||||
#[cfg(feature = "bevy_hierarchy")]
|
||||
use bevy_hierarchy::DespawnRecursiveExt;
|
||||
#[cfg(feature = "bevy_reflect")]
|
||||
use bevy_reflect::prelude::*;
|
||||
|
||||
use crate::state::{StateTransitionEvent, States};
|
||||
|
||||
|
@ -52,7 +56,8 @@ use crate::state::{StateTransitionEvent, States};
|
|||
/// app.enable_state_scoped_entities::<GameState>();
|
||||
/// 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);
|
||||
|
||||
/// Removes entities marked with [`StateScoped<S>`]
|
||||
|
|
Loading…
Reference in a new issue