11 个版本 (6 个稳定版)

2.0.0 2024 年 3 月 17 日
1.0.4 2022 年 12 月 26 日
0.1.4 2022 年 12 月 23 日

#252游戏开发

Download history 5/week @ 2024-03-10 144/week @ 2024-03-17 1/week @ 2024-03-24 110/week @ 2024-03-31 1/week @ 2024-04-07

每月下载量 340 次

MIT/Apache

18KB
164

Bevy ECS Markers

Crates.io MIT/Apache 2.0

添加了对标记实体和在查询中获取它们的支持

示例

查看更多示例 此处

#[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}");
}

许可

任选其一。

依赖

~9–37MB
~546K SLoC