ak_vis/viewer/picking.rs
1use bevy::prelude::*;
2
3pub fn update_material_on<E: EntityEvent>(
4 new_material: Handle<StandardMaterial>,
5) -> impl Fn(On<E>, Query<&mut MeshMaterial3d<StandardMaterial>>) {
6 // An observer closure that captures `new_material`. We do this to avoid needing to write four
7 // versions of this observer, each triggered by a different event and with a different hardcoded
8 // material. Instead, the event type is a generic, and the material is passed in.
9 move |event, mut query| {
10 if let Ok(mut material) = query.get_mut(event.event_target()) {
11 material.0 = new_material.clone();
12 }
13 }
14}