Easily attach bevy's Handles/Entities statically to types on startup and get them in any system, without using Resources.
It's just a little less clutter, and a bit more descriptive: e.g. Image::get_icon()
would return a weak clone of the Handle set with Image::set_icon(img_handle)
. The setter can only be used once! This is only useful if you're sure these Handles/Entities will never change (and are always available)! For a more general use case, see type_cell.
rust
use bevy_cell::*;
// setup cells
handle_cell!{Image: handle_a;}
entity_cell!{entity_a}
// on startup
Image::set_handle_a(img_handle);
Entity::set_entity_a(entity);
// in any system
Image::get_handle_a();
Entity::get_entity_a();
The macro also accepts multiple definitions at once:
rust
handle_cell!{
Image: image_a, image_b, image_c;
Mesh: mesh_a, mesh_b;
}
handle_cell!{ @Vec
Image: image_vec_a, image_vec_b, image_vec_c;
Mesh: mesh_vec_a, mesh_vec_b;
}
entity_cell!{
entity_a, entity_b, entity_c
}
For Vec/HashMaps:
rust
handle_cell!{@Vec Image: numbers;}
handle_cell!{@HashMap<K> Image: numbers_id;}
entity_cell!{@Vec slots}
entity_cell!{@HashMap<K> slots_id}
// on startup
Image::set_numbers(img_handle_vec);
Image::set_numbers_id(img_handle_map);
Entity::set_slots(entity_vec);
Entity::set_slots_id(entity_map);
// in any system
Image::get_numbers(index);
Image::get_numbers_id(key);
Entity::get_slots(index);
Entity::get_slots_id(key);
```rust use bevy_cell::; use bevy::prelude::;
handlecell!{Image: number;} entitycell!{slot}
fn startup (
mut cmd: Commands,
assets: Res
fn update (
mut timer: ResMut
struct ChangeTimer(Timer);
fn main () { let mut app = App::new(); app .addplugins(DefaultPlugins) .addsystems(Startup,startup) .addsystems(Update,update) .insertresource(ChangeTimer(Timer::from_seconds(1.,TimerMode::Once))) .run(); }
```
In handle_cell:
@Vec: save a Vec of handles, instead of just one
```rust use bevy_cell::; use bevy::prelude::;
handlecell!{@Vec #load #random Image: numbers;} entitycell!{slot}
fn startup (
mut cmd: Commands,
assets: Res
fn update (
mut timer: ResMut
struct ChangeTimer(Timer);
fn main () { let mut app = App::new(); app .addplugins(DefaultPlugins) .addsystems(Startup,startup) .addsystems(Update,update) .insertresource(ChangeTimer(Timer::from_seconds(1.,TimerMode::Repeating))) .run(); }
```