Use .register_asset_source() in extra_asset_source example (#12350)
# Objective Fixes #12347. ## Solution Use `.register_asset_source()` in `extra_asset_source` example instead of writing part of the app state.
This commit is contained in:
parent
512b7463a3
commit
f67b17d80d
@ -2,29 +2,25 @@
|
|||||||
//! This asset source exists in addition to the default asset source.
|
//! This asset source exists in addition to the default asset source.
|
||||||
|
|
||||||
use bevy::asset::{
|
use bevy::asset::{
|
||||||
io::{AssetSourceBuilder, AssetSourceBuilders, AssetSourceId},
|
io::{AssetSourceBuilder, AssetSourceId},
|
||||||
AssetPath,
|
AssetPath,
|
||||||
};
|
};
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut app = App::new();
|
App::new()
|
||||||
|
// Add an extra asset source with the name "example_files" to
|
||||||
// We add an extra asset source with the name "example_files" to the
|
// AssetSourceBuilders.
|
||||||
// AssetSourceBuilders.
|
//
|
||||||
// This needs to be done before AssetPlugin finalizes building them
|
// This must be done before AssetPlugin finalizes building assets.
|
||||||
let mut sources = app
|
.register_asset_source(
|
||||||
.world
|
"example_files",
|
||||||
.get_resource_or_insert_with::<AssetSourceBuilders>(default);
|
AssetSourceBuilder::platform_default("examples/asset/files", None),
|
||||||
sources.insert(
|
)
|
||||||
"example_files",
|
// DefaultPlugins contains AssetPlugin so it must be added to our App
|
||||||
AssetSourceBuilder::platform_default("examples/asset/files", None),
|
// after inserting our new asset source.
|
||||||
);
|
.add_plugins(DefaultPlugins)
|
||||||
|
|
||||||
// DefaultPlugins contains AssetPlugin so it needs to be added to our App
|
|
||||||
// after inserting our new asset source
|
|
||||||
app.add_plugins(DefaultPlugins)
|
|
||||||
.add_systems(Startup, setup)
|
.add_systems(Startup, setup)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
@ -32,7 +28,7 @@ fn main() {
|
|||||||
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
commands.spawn(Camera2dBundle::default());
|
commands.spawn(Camera2dBundle::default());
|
||||||
|
|
||||||
// Now we can load the asset using our new asset source
|
// Now we can load the asset using our new asset source.
|
||||||
//
|
//
|
||||||
// The actual file path relative to workspace root is
|
// The actual file path relative to workspace root is
|
||||||
// "examples/asset/files/bevy_pixel_light.png".
|
// "examples/asset/files/bevy_pixel_light.png".
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user