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
 |         //
 | ||||||
|     let mut sources = app |         // This must be done before AssetPlugin finalizes building assets.
 | ||||||
|         .world |         .register_asset_source( | ||||||
|         .get_resource_or_insert_with::<AssetSourceBuilders>(default); |  | ||||||
|     sources.insert( |  | ||||||
|             "example_files", |             "example_files", | ||||||
|             AssetSourceBuilder::platform_default("examples/asset/files", None), |             AssetSourceBuilder::platform_default("examples/asset/files", None), | ||||||
|     ); |         ) | ||||||
| 
 |         // DefaultPlugins contains AssetPlugin so it must be added to our App
 | ||||||
|     // DefaultPlugins contains AssetPlugin so it needs to be added to our App
 |         // after inserting our new asset source.
 | ||||||
|     // after inserting our new asset source
 |         .add_plugins(DefaultPlugins) | ||||||
|     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
	 Antony
						Antony