直接通过world创建实体

system包含world参数属于独占system,为了性能考虑,一般不会大规模在每帧中使用独占system. 抛开这些场景,world还是很好用的.

fn add_help_text(app: &mut App) {
    app.world_mut()
        .spawn(Node {
            width: Val::Percent(100.0),
            height: Val::Percent(100.0),
            padding: UiRect::all(Val::Px(10.0)),
            align_items: AlignItems::FlexStart,
            justify_content: JustifyContent::FlexStart,
            flex_direction: FlexDirection::Row,
            ..default()
        })
        .with_children(|parent| {
            parent.spawn((
                Text(HELP_MSG.to_string()),
                TextColor(Color::srgb(0.9, 0.9, 0.9).with_alpha(0.4)),
                TextFont::from_font_size(18.0),
                Node {
                    padding: UiRect::all(Val::Px(10.0)),
                    justify_content: JustifyContent::Center,
                    align_items: AlignItems::Center,
                    ..default()
                },
            ));
        });
}

add_help_text就是一个插件,相比声明类型->实现Plugin, 只有App参数的函数做为插件真是简化了不少.

正常情况下,在插件system中会注册ecs的方方面面,要生成实体也是通过commands实现, 这个例子又一次简化了,直接通过app.world_mut()开始创建了,省了不少事.

上面的例子中,UI是不变的,所以直接通过独占system完成了,这个没有调度,估计是独占不受调度影响.

猜测此时的运行应该是在首帧之前.