1use bevy::prelude::*;
2use bevy_egui::EguiPlugin;
3use bevy_notify::*;
4
5fn main() {
6 let mut app = App::new();
7 app.add_plugins(DefaultPlugins)
9 .add_plugin(EguiPlugin)
10 .add_plugin(NotifyPlugin)
11 .insert_resource(Notifications(Toasts::default()));
12
13 app.add_startup_system(scene_setup)
15 .add_system(notify_example)
16 .run();
17}
18
19fn notify_example(key_input: Res<Input<KeyCode>>, mut events: ResMut<Events<Toast>>) {
20 if key_input.just_pressed(KeyCode::Space) {
21 events.send(Toast::success("Space pressed"));
22 }
23}
24
25fn scene_setup(
26 mut commands: Commands,
27 mut meshes: ResMut<Assets<Mesh>>,
28 mut materials: ResMut<Assets<StandardMaterial>>,
29) {
30 commands.spawn(Camera3dBundle {
31 transform: Transform::from_xyz(5.0, 5.0, 1.0).looking_at(Vec3::new(0.0, 0.3, 0.0), Vec3::Y),
32 ..default()
33 });
34 const HALF_SIZE: f32 = 1.0;
35 commands.spawn(DirectionalLightBundle {
36 directional_light: DirectionalLight {
37 shadow_projection: OrthographicProjection {
38 left: -HALF_SIZE,
39 right: HALF_SIZE,
40 bottom: -HALF_SIZE,
41 top: HALF_SIZE,
42 near: -10.0 * HALF_SIZE,
43 far: 10.0 * HALF_SIZE,
44 ..default()
45 },
46 shadows_enabled: true,
47 ..default()
48 },
49 ..default()
50 });
51 commands.spawn(PbrBundle {
52 mesh: meshes.add(Mesh::from(shape::Icosphere {
53 radius: 1.0,
54 ..default()
55 })),
56 material: materials.add(Color::rgb(1.0, 0.0, 0.3).into()),
57 transform: Transform {
58 translation: Vec3 {
59 x: 0.0,
60 y: 1.0,
61 z: 0.0,
62 },
63 ..default()
64 },
65 ..default()
66 });
67}