Clean up the simple_picking example (#15633)
## Solution - Removed superfluous `Pickable` components - Slightly simplified the code for updating the text color - Removed the `Pointer<Click>` observer from the mesh entirely since that doesn't support picking yet
This commit is contained in:
parent
0b9a461d5d
commit
2526410096
@ -18,19 +18,16 @@ fn setup(
|
|||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
) {
|
) {
|
||||||
commands
|
commands
|
||||||
.spawn((
|
.spawn(TextBundle {
|
||||||
TextBundle {
|
text: Text::from_section("Click Me to get a box", TextStyle::default()),
|
||||||
text: Text::from_section("Click Me to get a box", TextStyle::default()),
|
style: Style {
|
||||||
style: Style {
|
position_type: PositionType::Absolute,
|
||||||
position_type: PositionType::Absolute,
|
top: Val::Percent(12.0),
|
||||||
top: Val::Percent(12.0),
|
left: Val::Percent(12.0),
|
||||||
left: Val::Percent(12.0),
|
..default()
|
||||||
..default()
|
|
||||||
},
|
|
||||||
..Default::default()
|
|
||||||
},
|
},
|
||||||
Pickable::default(),
|
..Default::default()
|
||||||
))
|
})
|
||||||
.observe(
|
.observe(
|
||||||
|_click: Trigger<Pointer<Click>>,
|
|_click: Trigger<Pointer<Click>>,
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
@ -47,26 +44,18 @@ fn setup(
|
|||||||
)
|
)
|
||||||
.observe(|evt: Trigger<Pointer<Out>>, mut texts: Query<&mut Text>| {
|
.observe(|evt: Trigger<Pointer<Out>>, mut texts: Query<&mut Text>| {
|
||||||
let mut text = texts.get_mut(evt.entity()).unwrap();
|
let mut text = texts.get_mut(evt.entity()).unwrap();
|
||||||
let first = text.sections.first_mut().unwrap();
|
text.sections[0].style.color = WHITE.into();
|
||||||
first.style.color = WHITE.into();
|
|
||||||
})
|
})
|
||||||
.observe(|evt: Trigger<Pointer<Over>>, mut texts: Query<&mut Text>| {
|
.observe(|evt: Trigger<Pointer<Over>>, mut texts: Query<&mut Text>| {
|
||||||
let mut text = texts.get_mut(evt.entity()).unwrap();
|
let mut text = texts.get_mut(evt.entity()).unwrap();
|
||||||
let first = text.sections.first_mut().unwrap();
|
text.sections[0].style.color = BLUE.into();
|
||||||
first.style.color = BLUE.into();
|
|
||||||
});
|
});
|
||||||
// circular base
|
// circular base
|
||||||
commands
|
commands.spawn((
|
||||||
.spawn((
|
Mesh3d(meshes.add(Circle::new(4.0))),
|
||||||
Mesh3d(meshes.add(Circle::new(4.0))),
|
MeshMaterial3d(materials.add(Color::WHITE)),
|
||||||
MeshMaterial3d(materials.add(Color::WHITE)),
|
Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
|
||||||
Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
|
));
|
||||||
Pickable::default(),
|
|
||||||
))
|
|
||||||
.observe(|click: Trigger<Pointer<Click>>| {
|
|
||||||
let click = click.event();
|
|
||||||
println!("{click:?}");
|
|
||||||
});
|
|
||||||
// light
|
// light
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
PointLight {
|
PointLight {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user