列出所有资源类型
这个例子显示了如何打印所有被添加为资源的类型的列表。
fn print_resources(archetypes: &Archetypes, components: &Components) {
let mut r: Vec<String> = archetypes
.resource()
.components()
.map(|id| components.get_info(id).unwrap())
// get_short_name removes the path information
// i.e. `bevy_audio::audio::Audio` -> `Audio`
// if you want to see the path info replace
// `TypeRegistration::get_short_name` with `String::from`
.map(|info| TypeRegistration::get_short_name(info.name()))
.collect();
// sort list alphebetically
r.sort();
r.iter().for_each(|name| println!("{}", name));
}
请注意,这并 没有 给你打印每一个由 Bevy 提供的、作为资源类型的全面列表。它列出的是 当前添加到 应用程序中的所有资源的类型(所有由依赖插件或由你自己注册的,等等)。