use bevy::app::AppExit; use bevy::prelude::*; use bevy_inspector_egui::quick::WorldInspectorPlugin; use futures::future::join_all; use futures::FutureExt; use bevy_async_system::prelude::*; fn main() { App::new() .add_plugins(( DefaultPlugins, WorldInspectorPlugin::new(), AsyncSystemPlugin )) .add_systems(Startup, setup_async_systems) .run(); } fn setup_async_systems(mut commands: Commands) { commands.spawn_async(|schedules| async move { schedules.add_system(Update, once::run(setup_blocks)).await; schedules.add_system(PreUpdate, once::insert_resource(MoveTimer(Timer::from_seconds(5., TimerMode::Once)))).await; schedules.add_system(PreUpdate, once::init_resource::()).await; let h1 = schedules.add_system(FixedUpdate, wait::until(move_block1)); let h2 = schedules.add_system(FixedUpdate, wait::until(rotate_block1)); let h3 = schedules.add_system(FixedUpdate, wait::until(rotate_block2)); join_all(vec![h1.boxed(), h2.boxed(), h3.boxed()]).await; schedules.add_system(PreUpdate, once::run(setup_count_down_ui)).await; schedules.add_system(PreUpdate, once::init_resource::()).await; schedules.add_system(Update, wait::until(count_down)).await; info!("AppExit"); schedules.add_system(Update, once::send(AppExit)).await; }); } #[derive(Resource, Clone)] struct MoveTimer(Timer); #[derive(Resource, Clone)] struct RotateTimer(Timer); impl Default for RotateTimer { fn default() -> Self { Self(Timer::from_seconds(3., TimerMode::Once)) } } #[derive(Component)] struct Block1; #[derive(Component)] struct Block2; fn setup_blocks( mut commands: Commands, mut materials: ResMut>, mut meshes: ResMut>, ) { commands.spawn(Camera3dBundle { transform: Transform::from_xyz(0.0, 6., 12.0).looking_at(Vec3::new(0., 1., 0.), Vec3::Y), ..default() }); commands.spawn(( Block1, Name::new("Block1"), PbrBundle { material: materials.add(StandardMaterial { base_color: Color::BLUE, ..default() }), mesh: meshes.add(shape::Box::default().into()), transform: Transform::from_xyz(3., -3., 3.), ..default() } )); commands.spawn(( Block2, Name::new("Block2"), PbrBundle { material: materials.add(StandardMaterial { base_color: Color::GREEN, ..default() }), mesh: meshes.add(shape::Box::default().into()), ..default() } )); } fn move_block1( mut block1: Query<&mut Transform, With>, time: Res