From 16922f87e65c86ac49be47b1b81ec587946cf0e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Pazos=20P=C3=A9rez?= Date: Tue, 25 Apr 2023 00:46:09 +0200 Subject: [PATCH] Add again loading set and fix example --- bevy_asset_loader/examples/progress_tracking.rs | 1 - bevy_asset_loader/src/loading_state.rs | 12 ++++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/bevy_asset_loader/examples/progress_tracking.rs b/bevy_asset_loader/examples/progress_tracking.rs index 3dccdc5..61b777f 100644 --- a/bevy_asset_loader/examples/progress_tracking.rs +++ b/bevy_asset_loader/examples/progress_tracking.rs @@ -15,7 +15,6 @@ fn main() { App::new() .add_plugins(DefaultPlugins) .add_state::() - .init_resource::() .add_loading_state(LoadingState::new(MyStates::AssetLoading)) .add_collection_to_loading_state::<_, TextureAssets>(MyStates::AssetLoading) .add_collection_to_loading_state::<_, AudioAssets>(MyStates::AssetLoading) diff --git a/bevy_asset_loader/src/loading_state.rs b/bevy_asset_loader/src/loading_state.rs index 51cf63b..02d6eda 100644 --- a/bevy_asset_loader/src/loading_state.rs +++ b/bevy_asset_loader/src/loading_state.rs @@ -387,7 +387,8 @@ where .add_systems( OnEnter(self.loading_state.clone()), reset_loading_state::, - ); + ) + .configure_set(Update, LoadingStateSet(self.loading_state.clone())); let mut loading_state_schedule = app.get_schedule_mut(loading_state_schedule).unwrap(); loading_state_schedule .configure_set( @@ -420,12 +421,15 @@ where Update, run_loading_state:: .in_set(TrackedProgressSet) + .in_set(LoadingStateSet(self.loading_state.clone())) .run_if(in_state(self.loading_state)), ); #[cfg(not(feature = "progress_tracking"))] app.add_systems( Update, - run_loading_state::.run_if(in_state(self.loading_state)), + run_loading_state:: + .in_set(LoadingStateSet(self.loading_state.clone())) + .run_if(in_state(self.loading_state)), ); } @@ -437,6 +441,10 @@ where } } +/// Systems in this set check the loading state of assets and will change the [`InternalLoadingState`] accordingly. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, SystemSet)] +pub(crate) struct LoadingStateSet(S); + #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, SystemSet)] pub(crate) enum InternalLoadingStateSet { Initialize,