From a29d962a758927250a39e052158a82264465ff44 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Thu, 28 Sep 2023 10:59:47 -0700 Subject: [PATCH] Add GI toggle to example --- examples/3d/solari.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/examples/3d/solari.rs b/examples/3d/solari.rs index cce693246e735..f6f083db69f9b 100644 --- a/examples/3d/solari.rs +++ b/examples/3d/solari.rs @@ -25,7 +25,8 @@ fn main() { ) .add_systems( Update, - (camera_controller, update_sun_direction).run_if(resource_exists::()), + (toggle_solari, camera_controller, update_sun_direction) + .run_if(resource_exists::()), ) .run(); } @@ -94,6 +95,25 @@ fn solari_not_supported(mut commands: Commands) { commands.spawn(Camera2dBundle::default()); } +fn toggle_solari( + key_input: Res>, + mut commands: Commands, + camera: Query<(Entity, Has), With>, +) { + if key_input.just_pressed(KeyCode::Space) { + let (entity, gi_enabled) = camera.single(); + if gi_enabled { + commands + .entity(entity) + .remove::(); + } else { + commands + .entity(entity) + .insert(SolariGlobalIlluminationSettings::default()); + } + } +} + // -------------------------------------------------------------------------------------- use bevy::input::mouse::MouseMotion;