1use bevy::{diagnostic::FrameCount, prelude::*};
4
5fn main() {
6 App::new()
9 .add_plugins(DefaultPlugins.set(WindowPlugin {
10 primary_window: Some(Window {
11 title: "Minimizing".into(),
12 ..default()
13 }),
14 ..default()
15 }))
16 .add_systems(Startup, (setup_3d, setup_2d))
17 .add_systems(Update, minimize_automatically)
18 .run();
19}
20
21fn minimize_automatically(mut window: Single<&mut Window>, frames: Res<FrameCount>) {
22 if frames.0 != 60 {
23 return;
24 }
25
26 window.set_minimized(true);
27}
28
29fn setup_3d(
31 mut commands: Commands,
32 mut meshes: ResMut<Assets<Mesh>>,
33 mut materials: ResMut<Assets<StandardMaterial>>,
34) {
35 commands.spawn((
37 Mesh3d(meshes.add(Plane3d::default().mesh().size(5.0, 5.0))),
38 MeshMaterial3d(materials.add(Color::srgb(0.3, 0.5, 0.3))),
39 ));
40 commands.spawn((
42 Mesh3d(meshes.add(Cuboid::default())),
43 MeshMaterial3d(materials.add(Color::srgb(0.8, 0.7, 0.6))),
44 Transform::from_xyz(0.0, 0.5, 0.0),
45 ));
46 commands.spawn((
48 PointLight {
49 shadows_enabled: true,
50 ..default()
51 },
52 Transform::from_xyz(4.0, 8.0, 4.0),
53 ));
54 commands.spawn((
56 Camera3d::default(),
57 Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
58 ));
59}
60
61fn setup_2d(mut commands: Commands) {
63 commands.spawn((
64 Camera2d,
65 Camera {
66 order: 1,
68 clear_color: ClearColorConfig::None,
70 ..default()
71 },
72 ));
73 commands.spawn(Sprite::from_color(
74 Color::srgb(0.25, 0.25, 0.75),
75 Vec2::new(50.0, 50.0),
76 ));
77}