Crates.io | ron_asset_manager |
lib.rs | ron_asset_manager |
version | 0.1.1 |
source | src |
created_at | 2024-11-09 10:51:38.766628 |
updated_at | 2024-11-09 11:03:31.827312 |
description | A dead simple crate to manage Ron based assets which depend on other assets. |
homepage | |
repository | https://github.com/Lommix/ron_asset_manager.git |
max_upload_size | |
id | 1441976 |
size | 18,794 |
A dead simple crate to manage Ron based assets which depend on other assets.
Assets can hot reload into a running game state. Use it to your advantage!
Shandle<T>
is a thin wrapper around Handle<T>
that can be serialized by
behaving like a asset path in serialized form.
This crates provides the RonAsset
derive macro, RonAssetPlugin
and the Shandle
.
The idea is to mark asset dependencies via attribute.
Currently there is #[asset]
, #[asset_vec]
, #[asset_map]
.
#[derive(Asset, TypePath, RonAsset, Deserialize)]
pub struct Wizard{
#[asset]
pub sprite: Shandle<Image>,
#[asset_map]
pub sound: HashMap<String, Shandle<AudioSource>>,
#[asset_vec]
pub spells: Vec<Shandle<Actions>>,
}
// also you need to register your type.
fn build(&self, app: &mut App) {
app.add_plugins(RonAssetPlugin::<Wizard>::default());
}
// that's all, time to use it
fn spawn_wizard(server: Res<AssetServer>){
let wizard_handle = server.load("/enemies/wizard.ron")
...
}
(
sprite: "sprite/wizard.png",
spells: {
"death" : "audio/wizard_death.ogg",
"hit" : "audio/wizard_hit.ogg",
"angry" : "audio/wizard_angy.ogg",
},
spells: (
"spells/fireball.ron",
"spells/lightning.ron",
)
)
Nested structs via another attribute #[ron_struct(field1, field2)]
.