Build production-ready editor authoring workflows
CI / Format, lint, test, build (push) Waiting to run

This commit is contained in:
Rbanh committed 2026-07-11 12:41:04 -04:00
1 parent cc1fa6ea3b
commit 0553a85220
163 files changed
+34547 -1565

No files matched your search

+85 -6
View File
@@ -14,14 +14,15 @@ use bevy::render::render_resource::{
};
use bevy::shader::ShaderRef;
use shared::{
ActorKind, AuthoringLightKind, ColliderDesc, LevelObject, LightDesc, ModelRef, ObjectiveMarker,
PhysicsBody, PlayerSpawn, PostProcessVolumeDesc, PrefabInstance, PrefabRef, Primitive,
RaytracingExcluded, StaticMeshRenderer, TeamSpawn, TriggerVolume, WeaponSpawn,
ActorKind, AudioListenerDesc, AudioSourceDesc, AuthoringLightKind, ColliderDesc, LevelObject,
LightDesc, ModelRef, ObjectiveMarker, PhysicsBody, PlayerSpawn, PostProcessVolumeDesc,
PrefabInstance, PrefabRef, Primitive, RaytracingExcluded, StaticMeshRenderer, TeamSpawn,
TriggerVolume, WeaponSpawn,
};
use crate::camera::EditorCamera;
use crate::infra::EditorOnly;
use crate::state::scene_tools_active;
use crate::state::{EditorMode, PlayPossession};
use crate::ui::UiState;
use crate::viewport::ViewportDisplayMode;
use crate::visualizers::EditorVisualizationSettings;
@@ -167,6 +168,8 @@ enum ActorIconImage {
LightPoint,
LightSpot,
LightDirectional,
AudioSource,
AudioListener,
PhysicsCollider,
GameSpawn,
GameTrigger,
@@ -180,6 +183,7 @@ enum ActorIconCategory {
Actor,
Mesh,
Light,
Audio,
Physics,
Gameplay,
Volume,
@@ -208,6 +212,8 @@ struct ActorIconComponents {
has_post_process_volume: bool,
has_team_spawn: bool,
has_objective: bool,
has_audio_source: bool,
has_audio_listener: bool,
has_physics: bool,
}
@@ -232,7 +238,7 @@ impl Plugin for ActorIconsPlugin {
app.init_resource::<ActorIconSettings>()
.add_plugins(MaterialPlugin::<ActorIconOverlayMaterial>::default())
.add_systems(Startup, init_actor_icon_assets)
.add_systems(Update, sync_actor_icons.run_if(scene_tools_active));
.add_systems(Update, sync_actor_icons);
}
}
@@ -314,6 +320,8 @@ fn init_actor_icon_assets(
(ActorIconImage::LightPoint, ICON_09_LIGHT_POINT),
(ActorIconImage::LightSpot, ICON_10_LIGHT_SPOT),
(ActorIconImage::LightDirectional, ICON_11_LIGHT_DIRECTIONAL),
(ActorIconImage::AudioSource, ICON_15_AUDIO_SOURCE),
(ActorIconImage::AudioListener, ICON_16_AUDIO_LISTENER),
(ActorIconImage::PhysicsCollider, ICON_17_PHYSICS_COLLIDER),
(ActorIconImage::GameSpawn, ICON_21_GAME_SPAWN),
(ActorIconImage::GameTrigger, ICON_22_GAME_TRIGGER),
@@ -343,6 +351,8 @@ fn init_actor_icon_assets(
#[allow(clippy::type_complexity, clippy::too_many_arguments)]
fn sync_actor_icons(
mode: Res<State<EditorMode>>,
possession: Res<PlayPossession>,
display: Res<ViewportDisplayMode>,
settings: Res<EditorVisualizationSettings>,
icon_settings: Res<ActorIconSettings>,
@@ -376,11 +386,14 @@ fn sync_actor_icons(
),
(With<LevelObject>, Without<EditorOnly>),
>,
audio: Query<(Has<AudioSourceDesc>, Has<AudioListenerDesc>)>,
physics: Query<(), Or<(With<PhysicsBody>, With<ColliderDesc>)>>,
) {
let camera = active_editor_camera(&camera_query);
let mut desired = HashMap::new();
if !display.clean_game_view && settings.enabled && settings.show_actor_icons {
let tools_active = *mode.get() == EditorMode::Editing
|| (*mode.get() == EditorMode::Playing && *possession == PlayPossession::Ejected);
if tools_active && !display.clean_game_view && settings.enabled && settings.show_actor_icons {
for (
target,
global,
@@ -399,6 +412,7 @@ fn sync_actor_icons(
has_objective,
) in &actor_roots
{
let (has_audio_source, has_audio_listener) = audio.get(target).unwrap_or_default();
let components = ActorIconComponents {
kind: kind.copied(),
light_kind: light.map(|light| light.kind),
@@ -414,6 +428,8 @@ fn sync_actor_icons(
has_post_process_volume,
has_team_spawn,
has_objective,
has_audio_source,
has_audio_listener,
has_physics: physics.contains(target),
};
let spec = icon_for_actor_components(components);
@@ -466,6 +482,7 @@ fn sync_actor_icons(
if existing_targets.contains(&target) {
continue;
}
let (has_audio_source, has_audio_listener) = audio.get(target).unwrap_or_default();
let components = ActorIconComponents {
kind: kind.copied(),
light_kind: light.map(|light| light.kind),
@@ -481,6 +498,8 @@ fn sync_actor_icons(
has_post_process_volume,
has_team_spawn,
has_objective,
has_audio_source,
has_audio_listener,
has_physics: physics.contains(target),
};
let spec = icon_for_actor_components(components);
@@ -578,6 +597,7 @@ fn icon_category_enabled(
ActorIconCategory::Actor => settings.show_actor_icon_actor,
ActorIconCategory::Mesh => settings.show_actor_icon_mesh,
ActorIconCategory::Light => settings.show_actor_icon_light,
ActorIconCategory::Audio => settings.show_actor_icon_audio,
ActorIconCategory::Physics => settings.show_actor_icon_physics,
ActorIconCategory::Gameplay => settings.show_actor_icon_gameplay,
ActorIconCategory::Volume => settings.show_actor_icon_volume,
@@ -712,6 +732,26 @@ fn icon_for_actor_components(components: ActorIconComponents) -> ActorIconSpec {
warning
}
}
ActorKind::AudioSource => {
if components.has_audio_source {
ActorIconSpec {
image: ActorIconImage::AudioSource,
category: ActorIconCategory::Audio,
}
} else {
warning
}
}
ActorKind::AudioListener => {
if components.has_audio_listener {
ActorIconSpec {
image: ActorIconImage::AudioListener,
category: ActorIconCategory::Audio,
}
} else {
warning
}
}
ActorKind::Empty => {
if components.has_physics {
ActorIconSpec {
@@ -767,6 +807,45 @@ mod tests {
assert_eq!(spec.category, ActorIconCategory::Physics);
}
#[test]
fn audio_source_and_listener_use_dedicated_icons() {
let source = icon_for_actor_components(ActorIconComponents {
kind: Some(ActorKind::AudioSource),
has_audio_source: true,
..default()
});
let listener = icon_for_actor_components(ActorIconComponents {
kind: Some(ActorKind::AudioListener),
has_audio_listener: true,
..default()
});
assert_eq!(source.image, ActorIconImage::AudioSource);
assert_eq!(source.category, ActorIconCategory::Audio);
assert_eq!(listener.image, ActorIconImage::AudioListener);
assert_eq!(listener.category, ActorIconCategory::Audio);
}
#[test]
fn audio_actor_without_matching_descriptor_uses_warning_icon() {
let spec = icon_for_actor_components(ActorIconComponents {
kind: Some(ActorKind::AudioSource),
..default()
});
assert_eq!(spec.image, ActorIconImage::Warning);
assert_eq!(spec.category, ActorIconCategory::Debug);
}
#[test]
fn audio_icon_category_respects_its_viewport_toggle() {
let mut settings = EditorVisualizationSettings::default();
assert!(icon_category_enabled(&settings, ActorIconCategory::Audio));
settings.show_actor_icon_audio = false;
assert!(!icon_category_enabled(&settings, ActorIconCategory::Audio));
}
#[test]
fn perspective_icon_size_uses_view_depth() {
let camera = GlobalTransform::IDENTITY;