mirror of
https://github.com/bevyengine/bevy
synced 2024-12-20 18:13:10 +00:00
d92fc1e456
# Objective Make documentation of a component's required components more visible by moving it to the type's docs ## Solution Change `#[require]` from a derive macro helper to an attribute macro. Disadvantages: - this silences any unused code warnings on the component, as it is used by the macro! - need to import `require` if not using the ecs prelude (I have not included this in the migration guilde as Rust tooling already suggests the fix) --- ## Showcase ![Documentation of Camera](https://github.com/user-attachments/assets/3329511b-747a-4c8d-a43e-57f7c9c71a3c) --------- Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com> Co-authored-by: JMS55 <47158642+JMS55@users.noreply.github.com>
25 lines
1.1 KiB
Rust
25 lines
1.1 KiB
Rust
use bevy_asset::Handle;
|
|
use bevy_derive::{Deref, DerefMut};
|
|
use bevy_ecs::component::{require, Component};
|
|
use bevy_reflect::Reflect;
|
|
use bevy_transform::components::Transform;
|
|
use derive_more::derive::From;
|
|
|
|
#[cfg(feature = "bevy_render")]
|
|
use bevy_render::view::visibility::Visibility;
|
|
|
|
use crate::{DynamicScene, Scene};
|
|
|
|
/// Adding this component will spawn the scene as a child of that entity.
|
|
/// Once it's spawned, the entity will have a [`SceneInstance`](crate::SceneInstance) component.
|
|
#[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect, PartialEq, Eq, From)]
|
|
#[require(Transform)]
|
|
#[cfg_attr(feature = "bevy_render", require(Visibility))]
|
|
pub struct SceneRoot(pub Handle<Scene>);
|
|
|
|
/// Adding this component will spawn the scene as a child of that entity.
|
|
/// Once it's spawned, the entity will have a [`SceneInstance`](crate::SceneInstance) component.
|
|
#[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect, PartialEq, Eq, From)]
|
|
#[require(Transform)]
|
|
#[cfg_attr(feature = "bevy_render", require(Visibility))]
|
|
pub struct DynamicSceneRoot(pub Handle<DynamicScene>);
|