-
-
Notifications
You must be signed in to change notification settings - Fork 175
/
deselection.rs
56 lines (52 loc) · 1.78 KB
/
deselection.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
//! This example is identical to the minimal example, except a cube has been added that when clicked
//! on, won't deselect anything else you have selected.
use bevy::prelude::*;
use bevy_mod_picking::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins.set(low_latency_window_plugin()))
.add_plugins(DefaultPickingPlugins)
.insert_resource(DebugPickingMode::Normal)
.add_systems(Startup, setup)
.run();
}
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// cube with NoDeselect
commands
.spawn((
PbrBundle {
mesh: meshes.add(Cuboid::default()),
material: materials.add(Color::srgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(1.5, 0.5, 0.0),
..default()
},
PickableBundle::default(),
NoDeselect, // <- When this entity is clicked, other entities won't be deselected.
))
.remove::<PickSelection>(); // <- Removing this removes the entity's ability to be selected.
commands.spawn((
PbrBundle {
mesh: meshes.add(Cuboid::default()),
material: materials.add(Color::srgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
},
PickableBundle::default(),
));
commands.spawn(PointLightBundle {
transform: Transform::from_xyz(4.0, 8.0, 4.0),
point_light: PointLight {
shadows_enabled: true,
..default()
},
..default()
});
commands.spawn((Camera3dBundle {
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
},));
}