Skip to content

Instantly share code, notes, and snippets.

@valkum
Created September 19, 2019 19:34
Show Gist options
  • Save valkum/85b8f15952a4971107f0d17138340363 to your computer and use it in GitHub Desktop.
Save valkum/85b8f15952a4971107f0d17138340363 to your computer and use it in GitHub Desktop.
snippets of code
..in on_start
world.exec(
|(loader, mut scene, mut scene_map): (PrefabLoader<'_, ScenePrefabData>, Write<'_, Scene>, Write<'_, SceneMap>)| {
scene_map.insert(0,
loader.load(
Path::new("prefab")
.join("lightroom_0.ron")
.to_string_lossy(),
RonFormat,
self.progress.as_mut().unwrap(),
),
);
scene_map.insert(1,
loader.load(
Path::new("prefab")
.join("lightroom_1.ron")
.to_string_lossy(),
RonFormat,
self.progress.as_mut().unwrap(),
),
);
scene.handle = Some(scene_map.get(&0).unwrap().clone());
},
);
...
#[derive(Derivative)]
#[derivative(Default(bound = ""))]
pub struct Scene {
pub handle: Option<Handle<Prefab<ScenePrefabData>>>,
pub scene: Option<usize>,
pub entity: Option<Entity>,
pub animation_index: usize,
}
#[derive(Debug, SystemDesc, new)]
#[system_desc(name(SceneChangeSystemDesc))]
pub struct SceneChangeSystem;
impl<'a> System<'a> for SceneChangeSystem {
type SystemData = (
Entities<'a>,
Read<'a, UIState>,
Write<'a, Scene>,
Read<'a, SceneMap>,
WriteStorage<'a, Handle<Prefab<ScenePrefabData>>>,
);
fn run(&mut self, (entities, ui_state, mut scene, scene_map, mut prefabs): Self::SystemData) {
if scene.scene.is_none() || scene.scene.unwrap() != ui_state.scene {
scene.scene = Some(ui_state.scene);
let scene_handle = scene_map.get(&ui_state.scene).unwrap().clone();
if scene.entity.is_some() {
entities.delete(scene.entity.unwrap());
}
println!("Creating new parent entity for scene {}.", scene.scene.unwrap());
scene.entity = Some(entities.build_entity().with(scene_handle, &mut prefabs).build());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment