bevy/examples/scene/load_scene.rs

36 lines
1.1 KiB
Rust
Raw Normal View History

2020-05-22 00:21:33 +00:00
use bevy::prelude::*;
use serde::{Deserialize, Serialize};
fn main() {
App::build()
.add_default_plugins()
// Registering components informs Bevy that they exist. This allows them to be used when loading/saving scenes
// This step is only required if you want to load/save your components.
2020-05-22 00:21:33 +00:00
.register_component::<Test>()
.register_component::<Foo>()
2020-05-22 00:59:33 +00:00
// .add_startup_system(setup)
2020-05-22 00:21:33 +00:00
.add_startup_system(load_scene)
.run();
}
#[derive(Serialize, Deserialize, Clone)]
2020-05-22 00:21:33 +00:00
struct Test {
pub x: f32,
pub y: f32,
}
#[derive(Serialize, Deserialize, Clone)]
2020-05-22 00:21:33 +00:00
struct Foo {
pub value: String,
}
fn load_scene(_world: &mut World, resources: &mut Resources) {
let asset_server = resources.get::<AssetServer>().unwrap();
let mut scenes = resources.get_mut::<Assets<Scene>>().unwrap();
let scene_handle: Handle<Scene> = asset_server
.load_sync(&mut scenes, "assets/scene/load_scene_example.scn")
.unwrap();
let _scene= scenes.get(&scene_handle).unwrap();
// world.merge(scene)
}