11 个版本 (6 个稳定版)
2.0.0 | 2024 年 3 月 17 日 |
---|---|
1.0.4 | 2022 年 12 月 26 日 |
0.1.4 | 2022 年 12 月 23 日 |
#252 在 游戏开发
每月下载量 340 次
18KB
164 行
Bevy ECS Markers
添加了对标记实体和在查询中获取它们的支持
示例
查看更多示例 此处
#[derive(EntityMarker)]
enum Players {
Red,
Blue,
Green,
Yellow,
}
#[derive(Component)]
struct Player {
field: usize,
}
fn main() {
App::new()
.add_plugins(LogPlugin::default())
.init_marker::<Players>()
.add_systems(Startup, (setup, move_red_player).chain())
.run();
}
fn setup(mut commands: Commands, mut players: MarkerMut<Players>) {
players[Players::Red].assign(commands.spawn(Player { field: 2 }).id());
players[Players::Blue].assign(commands.spawn(Player { field: 5 }).id());
players[Players::Green].assign(commands.spawn(Player { field: 7 }).id());
players[Players::Yellow].assign(commands.spawn(Player { field: 1 }).id());
}
fn move_red_player(mut query: Query<&mut Player>, current: Marker<Players>) {
let Ok(mut player) = query.get_mut(current[Players::Red].id()) else {
warn!("Red Player not set yet!");
return;
};
let old = player.field;
player.field += 2;
let new = player.field;
info!("Player moved from field {old} to field {new}");
}
许可
- MIT 许可证 (LICENSE-MIT 或 http://opensource.org/licenses/MIT)
- Apache 许可证 2.0 (LICENSE-APACHE 或 http://www.apache.org/licenses/LICENSE-2.0)
任选其一。
依赖
~9–37MB
~546K SLoC