mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 12:43:34 +00:00
25bfa80e60
# Objective Yet another PR for migrating stuff to required components. This time, cameras! ## Solution As per the [selected proposal](https://hackmd.io/tsYID4CGRiWxzsgawzxG_g#Combined-Proposal-1-Selected), deprecate `Camera2dBundle` and `Camera3dBundle` in favor of `Camera2d` and `Camera3d`. Adding a `Camera` without `Camera2d` or `Camera3d` now logs a warning, as suggested by Cart [on Discord](https://discord.com/channels/691052431525675048/1264881140007702558/1291506402832945273). I would personally like cameras to work a bit differently and be split into a few more components, to avoid some footguns and confusing semantics, but that is more controversial, and shouldn't block this core migration. ## Testing I ran a few 2D and 3D examples, and tried cameras with and without render graphs. --- ## Migration Guide `Camera2dBundle` and `Camera3dBundle` have been deprecated in favor of `Camera2d` and `Camera3d`. Inserting them will now also insert the other components required by them automatically.
55 lines
1.7 KiB
Rust
55 lines
1.7 KiB
Rust
//! Example of loading an embedded asset.
|
|
|
|
use bevy::{
|
|
asset::{embedded_asset, io::AssetSourceId, AssetPath},
|
|
prelude::*,
|
|
};
|
|
use std::path::Path;
|
|
|
|
fn main() {
|
|
App::new()
|
|
.add_plugins((DefaultPlugins, EmbeddedAssetPlugin))
|
|
.add_systems(Startup, setup)
|
|
.run();
|
|
}
|
|
|
|
struct EmbeddedAssetPlugin;
|
|
|
|
impl Plugin for EmbeddedAssetPlugin {
|
|
fn build(&self, app: &mut App) {
|
|
// We get to choose some prefix relative to the workspace root which
|
|
// will be ignored in "embedded://" asset paths.
|
|
let omit_prefix = "examples/asset";
|
|
// Path to asset must be relative to this file, because that's how
|
|
// include_bytes! works.
|
|
embedded_asset!(app, omit_prefix, "files/bevy_pixel_light.png");
|
|
}
|
|
}
|
|
|
|
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|
commands.spawn(Camera2d);
|
|
|
|
// Each example is its own crate (with name from [[example]] in Cargo.toml).
|
|
let crate_name = "embedded_asset";
|
|
|
|
// The actual file path relative to workspace root is
|
|
// "examples/asset/files/bevy_pixel_light.png".
|
|
//
|
|
// We omit the "examples/asset" from the embedded_asset! call and replace it
|
|
// with the crate name.
|
|
let path = Path::new(crate_name).join("files/bevy_pixel_light.png");
|
|
let source = AssetSourceId::from("embedded");
|
|
let asset_path = AssetPath::from_path(&path).with_source(source);
|
|
|
|
// You could also parse this URL-like string representation for the asset
|
|
// path.
|
|
assert_eq!(
|
|
asset_path,
|
|
"embedded://embedded_asset/files/bevy_pixel_light.png".into()
|
|
);
|
|
|
|
commands.spawn(SpriteBundle {
|
|
texture: asset_server.load(asset_path),
|
|
..default()
|
|
});
|
|
}
|