2个版本
0.14.2 | 2024年8月12日 |
---|---|
0.14.1 | 2024年8月10日 |
816 在 游戏开发
每月240次下载
34KB
613 行
此crate提供了一种简单易用的方式来创建仅对单个实体操作的系统。
#[derive(Component)]
struct MyMarkerComponent;
fn my_entity_system(data: Data<&mut Transform, With<MyMarkerComponent>>, mut commands: Commands) {
*data.item += 10;
commands.spawn(Transform::from_translation(data.item.translation));
}
fn my_entity_system_with_input(input: In<Vec2>, data: Data<&mut Transform>) {
*data.item += input;
}
app.add_systems(Update, (
my_entity_system.into_system(),
my_entity_system_with_input.into_system()
));
lib.rs
:
此crate提供了一种简单易用的方式来创建仅对单个实体操作的系统。
#[derive(Component)]
struct Count(i32);
#[derive(Component)]
struct MyMarkerComponent;
fn my_entity_system(
mut data: Data<&mut Count, With<MyMarkerComponent>>,
mut commands: Commands
) {
data.item.0 += 1;
commands.spawn(Count(10));
}
fn my_entity_system_with_input(input: In<i32>, mut data: Data<&mut Count>) {
data.item.0 += *input;
}
bevy_ecs::system::assert_is_system(my_entity_system.into_system());
bevy_ecs::system::assert_is_system(my_entity_system_with_input.into_system());
依赖
~7–10MB
~172K SLoC