假设我有这样的事情:
use bevy::prelude::*;
// Bevy style tag
struct &CharacterBox;
// Somewhere to store the entity
pub struct Action {
pub character_box: Option<Entity>,
};
fn setup( mut commands: Commands, mut action: ResMut<Action> ) {
if let Some(entity) = commands
.spawn(UiCameraComponents::default())
.spawn(NodeComponents { /* snip */ })
.with_children(|p| {
p.spawn(ButtonComponents { /* snip, snap */ });
})
.with(CharacterBox)
.current_entity()
{
action.character_box = Some(entity);
}
}
一个带有一两个按钮的 NodeComponents 从启动...
...后来我想从我添加的系统中添加更多按钮:
fn do_actions(
mut commands: Commands,
action: ChangedRes<Action>,
mut query: Query<(&CharacterBox, &Children)>,
) {
if let Some(entity) = commands
.spawn(ButtonComponents { /* ... */ })
.current_entity()
{
let mut charbox = query.get_mut::<Children>(action.character_box.unwrap()).unwrap();
// I know this is naïve, I know I can't just push in the entity,
// but it illustrates my point...
charbox.push(entity); // How do I achieve this?
}
}
如何将我生成的实体(组件?)插入我的 NodeComponents.Children?
如何将组件生成到已经存在的组件中?
或者我如何访问 NodeComponents.Children.ChildBuilder?我可以查询 ChildBuilders 吗?
编辑:删除的编辑。