Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/crates/bevy_scene/src/spawn_system.rs
30635 views
1
use crate::{Scene, SceneList, WorldSceneExt};
2
use bevy_ecs::{error::Result, world::World};
3
4
/// Returns a system that spawns the given [`Scene`]. This should generally only be added to
5
/// schedules that run once, such as [`Startup`](bevy_app::Startup).
6
pub trait SpawnSystem {
7
/// Returns a system that spawns the given [`Scene`]. This should generally only be added to
8
/// schedules that run once, such as [`Startup`](bevy_app::Startup).
9
fn spawn(self) -> impl FnMut(&mut World) -> Result;
10
}
11
12
impl<F: FnMut() -> S + Send + Sync + 'static, S: Scene> SpawnSystem for F {
13
fn spawn(mut self) -> impl FnMut(&mut World) -> Result {
14
move |world: &mut World| -> Result {
15
world.spawn_scene(self())?;
16
Ok(())
17
}
18
}
19
}
20
21
/// Returns a system that spawns the given [`SceneList`]. This should generally only be added to
22
/// schedules that run once, such as [`Startup`](bevy_app::Startup).
23
pub trait SpawnListSystem {
24
/// Returns a system that spawns the given [`SceneList`]. This should generally only be added to
25
/// schedules that run once, such as [`Startup`](bevy_app::Startup).
26
fn spawn(self) -> impl FnMut(&mut World) -> Result;
27
}
28
impl<F: FnMut() -> S + Send + Sync + 'static, S: SceneList> SpawnListSystem for F {
29
fn spawn(mut self) -> impl FnMut(&mut World) -> Result {
30
move |world: &mut World| -> Result {
31
world.spawn_scene_list(self())?;
32
Ok(())
33
}
34
}
35
}
36
37