我不确定我是否混淆了 Bevy 的变更检测系统的功能,或者我只是做错了。但是,在尝试检测更改时,我只会在组件生成时收到通知。
下面,我spawn
是一个元组Group,Size(2)
。然后,sizequery
每帧运行一次,直到大小为 5。这一次,groupsize
只运行一次,大小为 2。这是为什么呢?
use bevy:: {
prelude::*,
};
fn main () {
App::build()
.add_resource(WindowDescriptor {
..Default::default()
})
.add_default_plugins()
.add_startup_system(setup.system())
.add_plugin(TestPlugin)
.run();
}
struct Group;
struct Size(u32);
fn setup(mut commands: Commands) {
commands.spawn((Group,Size(2)));
}
fn groupsize(mut query: Query<Changed<Size>>) {
for s in &mut query.iter() {
println!("GS-{}",s.0);
}
}
fn sizequery(mut query: Query<&mut Size>) {
for mut s in &mut query.iter() {
if s.0 < 5 {
s.0 = s.0+1;
println!("add{}",s.0);
}
}
}
pub struct TestPlugin;
impl Plugin for TestPlugin {
fn build(&self, app: &mut AppBuilder) {
app.add_system(groupsize.system());
app.add_system(sizequery.system());
}
}
货物.toml:
[package]
name = "bevy_test"
version = "0.1.0"
edition = "2018"
[dependencies]
bevy = "0.1.3"