gpt4 book ai didi

rust - Bevy "scope"如何根据参数类型对其系统进行处理?

转载 作者:行者123 更新时间:2023-12-03 11:23:43 25 4
gpt4 key购买 nike

Bevy ,一个新的 Rust 游戏引擎和 ECS,有一个特性,它根据参数的类型“范围”它的系统。来自 its docs :

The parameters we pass in to a "system function" define what entities the system runs on. In this case, greet_people will run on all entities with the Person and Name component.


它看起来像这样:
struct Person;
struct Name(String);

fn greet_people(person: &Person, name: &Name) {
println!("hello {}", name.0);
}
Bevy 是如何做到这一点的?我以为我在某处读到 Rust 不支持这种方式的反射。

最佳答案

Bevy 定义了一组特征( IntoQuerySystem IntoForEachSystem ),这些特征由匹配这些签名的函数实现。这些特征随后由 Bevy 序曲输出。这样做的一个限制是,您只能将最多具有一定数量参数的函数转换为系统,并且参数必须按特定顺序排列([command?]、[resources...]、[queries/components. ..])。
编辑:For-each 系统在 Bevy 0.4 中被弃用。

关于rust - Bevy "scope"如何根据参数类型对其系统进行处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63497233/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com