| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
use bevy::{ |
| 5 |
asset::{ |
| 6 |
io::{AssetSourceBuilder, AssetSourceId}, |
| 7 |
AssetPath, |
| 8 |
}, |
| 9 |
prelude::*, |
| 10 |
}; |
| 11 |
use std::path::Path; |
| 12 |
|
| 13 |
fn main() { |
| 14 |
App::new() |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
.register_asset_source( |
| 20 |
"example_files", |
| 21 |
AssetSourceBuilder::platform_default("examples/asset/files", None), |
| 22 |
) |
| 23 |
|
| 24 |
|
| 25 |
.add_plugins(DefaultPlugins) |
| 26 |
.add_systems(Startup, setup) |
| 27 |
.run(); |
| 28 |
} |
| 29 |
|
| 30 |
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) { |
| 31 |
commands.spawn(Camera2d); |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
let path = Path::new("bevy_pixel_light.png"); |
| 38 |
let source = AssetSourceId::from("example_files"); |
| 39 |
let asset_path = AssetPath::from_path(path).with_source(source); |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
assert_eq!(asset_path, "example_files://bevy_pixel_light.png".into()); |
| 44 |
|
| 45 |
commands.spawn(Sprite::from_image(asset_server.load(asset_path))); |
| 46 |
} |