Skip to content

Commit b67da4c

Browse files
committed
use single query
1 parent e0f2036 commit b67da4c

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

crate/src/lib.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -999,13 +999,18 @@ impl <T: Into<Color>> From<T> for UiColor {
999999
/// This system takes care of [`UiColor`] data and updates querried [`Sprite`] and [`TextColor`] components.
10001000
/// and updates [`ColorMaterial`] and [`StandardMaterial`]
10011001
pub fn system_color(
1002-
mut query: Query<(Entity, Option<&mut Sprite>, Option<&mut TextColor>, &UiColor, &UiState), Or<(Changed<UiColor>, Changed<UiState>)>>,
1003-
mat2d_ids: Query<&MeshMaterial2d<ColorMaterial>>,
1004-
mat3d_ids: Query<&MeshMaterial3d<StandardMaterial>>,
1002+
mut query: Query<(
1003+
Option<&mut Sprite>,
1004+
Option<&mut TextColor>,
1005+
Option<&MeshMaterial2d<ColorMaterial>>,
1006+
Option<&MeshMaterial3d<StandardMaterial>>,
1007+
&UiColor,
1008+
&UiState,
1009+
), Or<(Changed<UiColor>, Changed<UiState>)>>,
10051010
mut materials2d: ResMut<Assets<ColorMaterial>>,
10061011
mut materials3d: ResMut<Assets<StandardMaterial>>,
10071012
) {
1008-
for (e, node_sprite_option, node_text_option, node_color, node_state) in &mut query {
1013+
for (node_sprite_option, node_text_option, mat2d, mat3d, node_color, node_state) in &mut query {
10091014

10101015
// Normalize the active state weights
10111016
let mut total_weight = 0.0;
@@ -1051,11 +1056,11 @@ pub fn system_color(
10511056
if let Some(mut text) = node_text_option {
10521057
**text = blend_color.into();
10531058
}
1054-
if let Ok(id) = mat2d_ids.get(e) {
1059+
if let Some(id) = mat2d {
10551060
if let Some(mat) = materials2d.get_mut(id) {
10561061
mat.color = blend_color.into();
10571062
}
1058-
} else if let Ok(id) = mat3d_ids.get(e) {
1063+
} else if let Some(id) = mat3d {
10591064
if let Some(mat) = materials3d.get_mut(id) {
10601065
mat.base_color = blend_color.into();
10611066
}

0 commit comments

Comments
 (0)