是否可以通过使实体处于生锈状态来获取组件列表?例如用于调试目的。
use bevy::prelude::*;
fn main()
{
App::build()
.add_plugins(DefaultPlugins)
.add_startup_system(setup.system())
.add_system(first.system())
.add_system(first_no_second.system())
.add_system(first_and_second.system())
.run()
}
fn setup(mut commands: Commands)
{
commands.spawn().insert(FirstComponent(0.0));
commands.spawn().insert(FirstComponent(1.0));
commands.spawn().insert(SecondComponent::StateA);
commands.spawn().insert(SecondComponent::StateB);
commands.spawn().insert(SecondComponent::StateA).insert(FirstComponent(3.0));
commands.spawn().insert(SecondComponent::StateB).insert(FirstComponent(4.0));
}
#[derive(Debug)]
struct FirstComponent(f32);
#[derive(Debug)]
enum SecondComponent
{
StateA,
StateB
}
fn first(query: Query<&FirstComponent>)
{
for entity in query.iter()
{
println!("First: {:?}", entity)
}
}
fn first_no_second(query: Query<&FirstComponent, Without<SecondComponent>>)
{
for entity in query.iter()
{
println!("First without Second: {:?}", entity)
}
}
fn first_and_second(query: Query<&FirstComponent, With<SecondComponent>>)
{
for entity in query.iter()
{
println!("First with Second: {:?}", entity)
}
}
bevy 的 ecs 如何了解某个 Queue 需要启动哪些系统。在 World 中,组件在某种程度上与实体相关,对吗?是否有可能从外部以某种方式追踪这种联系?我真的很喜欢它的工作原理,对我来说它看起来很神奇,但我想了解“幕后”发生的事情