mirror of
https://github.com/storytold/storyteller-bevy.git
synced 2026-10-29 09:08:58 +00:00
add system, attempt to map to old path
This commit is contained in:
@@ -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 space_editor::prelude::EditorRegistryExt;
|
||||||
use crate::material::short_material::ShortMaterial;
|
use crate::material::short_material::ShortMaterial;
|
||||||
|
|
||||||
@@ -10,5 +13,26 @@ impl Plugin for MaterialPlugin {
|
|||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.register_type::<ShortMaterial>()
|
app.register_type::<ShortMaterial>()
|
||||||
.editor_registry::<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>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,7 +95,6 @@ impl Plugin for InspectorPlugin {
|
|||||||
.chain()
|
.chain()
|
||||||
.before(space_editor::space_prefab::sub_scene::prepare_auto_scene),
|
.before(space_editor::space_prefab::sub_scene::prepare_auto_scene),
|
||||||
);
|
);
|
||||||
app.add_systems(PostUpdate, apply_short_materials);
|
|
||||||
|
|
||||||
app.world.resource_mut::<InspectGetters>().getters.insert(
|
app.world.resource_mut::<InspectGetters>().getters.insert(
|
||||||
StandardMaterial::get_type_registration()
|
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)]
|
#[derive(Resource, Default)]
|
||||||
struct InspectGetters {
|
struct InspectGetters {
|
||||||
getters: HashMap<
|
getters: HashMap<
|
||||||
|
|||||||
Reference in New Issue
Block a user