This repository was archived by the owner on Oct 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.rs
58 lines (48 loc) · 1.63 KB
/
demo.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use bevy::prelude::*;
use bevy_mod_gizmos::*;
#[rustfmt::skip]
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(GizmosPlugin)
.add_startup_system(setup)
.add_system(update)
// This resource is used to showcase being able
// to run any system on hover and click
.init_resource::<GizmosOffset>()
.run();
}
#[derive(Resource, Default)]
struct GizmosOffset(Vec3);
fn setup(mut commands: Commands) {
println!("Trying hovering and clicking the center gizmo");
let cam_transform = Transform::from_xyz(0.0, 0.0, 8.0);
commands.spawn((
Camera3dBundle {
transform: cam_transform.looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
},
GizmoInteractionCamera,
));
}
// Notice this resource is read only,
// it is being mutated by the hover and click systems
fn update(offset: Res<GizmosOffset>) {
draw_gizmo(
Gizmo::new(Vec3::ZERO + offset.0, 1.0, Color::WHITE)
.on_click(|| println!("I've been clicked!"))
.on_hover(|| println!("Hovered"))
.on_hover_system(|mut offset: ResMut<GizmosOffset>, time: Res<Time>| {
offset.0.y -= 0.5 * time.delta_seconds();
})
.on_click_system(|mut offset: ResMut<GizmosOffset>| {
offset.0.y += 0.5;
}),
);
draw_gizmos_with_line(vec![
(Vec3::new(2.0, 2.0, 0.0) + offset.0, 0.5),
(Vec3::new(-2.0, 2.0, 0.0) + offset.0, 0.25),
(Vec3::new(-2.0, -2.0, 0.0) + offset.0, 0.75),
(Vec3::new(2.0, -2.0, 0.0) + offset.0, 1.0),
]);
}