add system, attempt to map to old path

This commit is contained in:
Brandon Thomas
2024-03-24 21:48:37 -04:00
parent d8bd54d0ba
commit d44170e8f4
2 changed files with 25 additions and 21 deletions
+25 -1
View File
@@ -1,4 +1,7 @@
use bevy::app::{App, Plugin};
use bevy::app::{App, Plugin, PostUpdate};
use bevy::asset::{Assets, Handle};
use bevy::pbr::StandardMaterial;
use bevy::prelude::{Commands, Entity, Query, ResMut};
use space_editor::prelude::EditorRegistryExt;
use crate::material::short_material::ShortMaterial;
@@ -10,5 +13,26 @@ impl Plugin for MaterialPlugin {
fn build(&self, app: &mut App) {
app.register_type::<ShortMaterial>()
.editor_registry::<ShortMaterial>();
app.add_systems(PostUpdate, apply_short_materials);
}
}
fn apply_short_materials(
mut commands: Commands,
q_mats: Query<(Entity, &Handle<StandardMaterial>, &ShortMaterial)>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
for (entity, handle, short) in q_mats.iter() {
let Some(material) = materials.get_mut(handle) else {
continue;
};
material.base_color = short.base_color;
material.perceptual_roughness = short.perceptual_roughness;
material.metallic = short.metallic;
material.reflectance = short.reflectance;
commands.entity(entity).remove::<ShortMaterial>();
}
}
-20
View File
@@ -95,7 +95,6 @@ impl Plugin for InspectorPlugin {
.chain()
.before(space_editor::space_prefab::sub_scene::prepare_auto_scene),
);
app.add_systems(PostUpdate, apply_short_materials);
app.world.resource_mut::<InspectGetters>().getters.insert(
StandardMaterial::get_type_registration()
@@ -143,25 +142,6 @@ fn create_short_materials(
}
}
fn apply_short_materials(
mut commands: Commands,
q_mats: Query<(Entity, &Handle<StandardMaterial>, &ShortMaterial)>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
for (entity, handle, short) in q_mats.iter() {
let Some(material) = materials.get_mut(handle) else {
continue;
};
material.base_color = short.base_color;
material.perceptual_roughness = short.perceptual_roughness;
material.metallic = short.metallic;
material.reflectance = short.reflectance;
commands.entity(entity).remove::<ShortMaterial>();
}
}
#[derive(Resource, Default)]
struct InspectGetters {
getters: HashMap<