//! An example of registering an extra asset source, and loading assets from it.1//! This asset source exists in addition to the default asset source.23use bevy::{4asset::{5io::{AssetSourceBuilder, AssetSourceId},6AssetPath,7},8prelude::*,9};10use std::path::Path;1112fn main() {13App::new()14// Add an extra asset source with the name "example_files" to15// AssetSourceBuilders.16//17// This must be done before AssetPlugin finalizes building assets.18.register_asset_source(19"example_files",20AssetSourceBuilder::platform_default("examples/asset/files", None),21)22// DefaultPlugins contains AssetPlugin so it must be added to our App23// after inserting our new asset source.24.add_plugins(DefaultPlugins)25.add_systems(Startup, setup)26.run();27}2829fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {30commands.spawn(Camera2d);3132// Now we can load the asset using our new asset source.33//34// The actual file path relative to workspace root is35// "examples/asset/files/bevy_pixel_light.png".36let path = Path::new("bevy_pixel_light.png");37let source = AssetSourceId::from("example_files");38let asset_path = AssetPath::from_path(path).with_source(source);3940// You could also parse this URL-like string representation for the asset41// path.42assert_eq!(asset_path, "example_files://bevy_pixel_light.png".into());4344commands.spawn(Sprite::from_image(asset_server.load(asset_path)));45}464748