Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix: hierarchy connection lines, entity visibility, and child creation

esengine9dc1d4558aec
diff --git a/editor/src/bounds/BoundsRegistry.ts b/editor/src/bounds/BoundsRegistry.ts
index 08270aa92..76fa477de 100644
--- a/editor/src/bounds/BoundsRegistry.ts
+++ b/editor/src/bounds/BoundsRegistry.ts
@@ -19,5 +19,5 @@ export function getEntityBounds(components: { type: string; data: any }[]): Boun
if (bounds) return bounds;
}
}
- return { width: 50, height: 50 };
+ return { width: 0, height: 0 };
}
diff --git a/editor/src/commands/EntityCommands.ts b/editor/src/commands/EntityCommands.ts
index b7e618b9d..e0ca4196a 100644
--- a/editor/src/commands/EntityCommands.ts
+++ b/editor/src/commands/EntityCommands.ts
@@ -184,6 +184,80 @@ export class ReparentCommand extends BaseCommand {
}
}
+// =============================================================================
+// MoveEntityCommand
+// =============================================================================
+
+export class MoveEntityCommand extends BaseCommand {
+ readonly type = 'move_entity';
+ readonly description: string;
+ private oldParent_: number | null;
+ private oldIndex_: number;
+
+ constructor(
+ private scene_: SceneData,
+ private entityId_: number,
+ private newParent_: number | null,
+ private newIndex_: number
+ ) {
+ super();
+ const entity = scene_.entities.find(e => e.id === entityId_);
+ this.oldParent_ = entity?.parent ?? null;
+ this.oldIndex_ = this.computeIndex(this.oldParent_);
+ this.description = `Move entity "${entity?.name ?? entityId_}"`;
+ }
+
+ execute(): void {
+ this.applyMove(this.newParent_, this.newIndex_);
+ }
+
+ undo(): void {
+ this.applyMove(this.oldParent_, this.oldIndex_);
+ }
+
+ private computeIndex(parent: number | null): number {
+ if (parent !== null) {
+ const parentData = this.scene_.entities.find(e => e.id === parent);
+ return parentData?.children.indexOf(this.entityId_) ?? 0;
+ }
+ const roots = this.scene_.entities.filter(e => e.parent === null);
+ return roots.findIndex(e => e.id === this.entityId_);
+ }
+
+ private applyMove(targetParent: number | null, targetIndex: number): void {
+ const entity = this.scene_.entities.find(e => e.id === this.entityId_);
+ if (!entity) return;
+
+ if (entity.parent !== null) {
+ const parent = this.scene_.entities.find(e => e.id === entity.parent);
+ if (parent) {
+ const idx = parent.children.indexOf(this.entityId_);
+ if (idx !== -1) parent.children.splice(idx, 1);
+ }
+ }
+
+ entity.parent = targetParent;
+
+ if (targetParent !== null) {
+ const parent = this.scene_.entities.find(e => e.id === targetParent);
+ if (parent) {
+ const i = Math.min(targetIndex, parent.children.length);
+ parent.children.splice(i, 0, this.entityId_);
+ }
+ } else {
+ const arrIdx = this.scene_.entities.indexOf(entity);
+ this.scene_.entities.splice(arrIdx, 1);
+ const roots = this.scene_.entities.filter(e => e.parent === null);
+ if (targetIndex >= roots.length) {
+ this.scene_.entities.push(entity);
+ } else {
+ const refIdx = this.scene_.entities.indexOf(roots[targetIndex]);
+ this.scene_.entities.splice(refIdx, 0, entity);
+ }
+ }
+ }
+}
+
// =============================================================================
// AddComponentCommand
// =============================================================================
diff --git a/editor/src/commands/index.ts b/editor/src/commands/index.ts
index 78c8a282e..5ff79625d 100644
--- a/editor/src/commands/index.ts
+++ b/editor/src/commands/index.ts
@@ -9,6 +9,7 @@ export {
CreateEntityCommand,
DeleteEntityCommand,
ReparentCommand,
+ MoveEntityCommand,
AddComponentCommand,
RemoveComponentCommand,
} from './EntityCommands';
diff --git a/editor/src/panels/HierarchyPanel.ts b/editor/src/panels/HierarchyPanel.ts
index b28eafa5b..4b358f39d 100644
--- a/editor/src/panels/HierarchyPanel.ts
+++ b/editor/src/panels/HierarchyPanel.ts
@@ -89,6 +89,17 @@ export class HierarchyPanel {
this.treeContainer_.addEventListener('click', (e) => {
const target = e.target as HTMLElement;
+ const visibilityBtn = target.closest('.es-hierarchy-visibility') as HTMLElement;
+ if (visibilityBtn) {
+ e.stopPropagation();
+ const item = visibilityBtn.closest('.es-hierarchy-item') as HTMLElement;
+ const entityId = parseInt(item?.dataset.entityId ?? '', 10);
+ if (!isNaN(entityId)) {
+ this.store_.toggleVisibility(entityId);
+ }
+ return;
+ }
+
const expandBtn = target.closest('.es-hierarchy-expand') as HTMLElement;
if (expandBtn) {
e.stopPropagation();
@@ -419,7 +430,7 @@ export class HierarchyPanel {
);
}
- this.treeContainer_.innerHTML = this.renderEntities(rootEntities, scene, selectedEntity);
+ this.treeContainer_.innerHTML = this.renderEntities(rootEntities, scene, selectedEntity, 0);
if (this.footerContainer_) {
const count = scene.entities.length;
@@ -470,7 +481,8 @@ export class HierarchyPanel {
private renderEntities(
entities: EntityData[],
scene: SceneData,
- selectedEntity: Entity | null
+ selectedEntity: Entity | null,
+ depth: number = 0
): string {
return entities.map(entity => {
const children = this.searchFilter_
@@ -484,18 +496,21 @@ export class HierarchyPanel {
const icon = this.getEntityIcon(entity);
const type = this.getEntityType(entity);
const expandIcon = isExpanded ? icons.chevronDown(10) : icons.chevronRight(10);
+ const isVisible = this.store_.isEntityVisible(entity.id);
+ const visibilityIcon = isVisible ? icons.eye(10) : icons.eyeOff(10);
+ const hiddenClass = isVisible ? '' : ' es-entity-hidden';
return `
- <div class="es-hierarchy-item ${isSelected ? 'es-selected' : ''} ${hasChildren ? 'es-has-children' : ''} ${isExpanded ? 'es-expanded' : ''}"
- data-entity-id="${entity.id}">
- <div class="es-hierarchy-row" draggable="true">
- <span class="es-hierarchy-visibility">${icons.eye(10)}</span>
+ <div class="es-hierarchy-item ${isSelected ? 'es-selected' : ''}${hiddenClass} ${hasChildren ? 'es-has-children' : ''} ${isExpanded ? 'es-expanded' : ''}"
+ data-entity-id="${entity.id}" style="--depth: ${depth}">
+ <div class="es-hierarchy-row" draggable="true" style="padding-left: ${8 + depth * 16}px">
${hasChildren ? `<span class="es-hierarchy-expand">${expandIcon}</span>` : '<span class="es-hierarchy-spacer"></span>'}
+ <span class="es-hierarchy-visibility">${visibilityIcon}</span>
<span class="es-hierarchy-icon">${icon}</span>
<span class="es-hierarchy-name">${this.escapeHtml(entity.name)}</span>
<span class="es-hierarchy-type">${type}</span>
</div>
- ${hasChildren && isExpanded ? `<div class="es-hierarchy-children">${this.renderEntities(children, scene, selectedEntity)}</div>` : ''}
+ ${hasChildren && isExpanded ? `<div class="es-hierarchy-children">${this.renderEntities(children, scene, selectedEntity, depth + 1)}</div>` : ''}
</div>
`;
}).join('');
diff --git a/editor/src/panels/InspectorPanel.ts b/editor/src/panels/InspectorPanel.ts
index 2795b6a73..945b17179 100644
--- a/editor/src/panels/InspectorPanel.ts
+++ b/editor/src/panels/InspectorPanel.ts
@@ -268,6 +268,7 @@ export class InspectorPanel {
if (!entityChanged && !componentsChanged && !wasAsset) {
this.updateEditors();
+ this.updateVisibilityIcon();
const entityData = this.store_.getSelectedEntityData();
if (entityData) {
this.renderMaterialPreview(entity, entityData.components);
@@ -289,7 +290,6 @@ export class InspectorPanel {
}
this.renderEntityHeader(entityData.name, entity);
- this.renderTagsSection(entity);
for (const component of entityData.components) {
this.renderComponent(entity, component);
@@ -307,11 +307,15 @@ export class InspectorPanel {
}
private renderEntityHeader(name: string, entity: Entity): void {
+ const isVisible = this.store_.isEntityVisible(entity as number);
+ const visibilityIcon = isVisible ? icons.eye(14) : icons.eyeOff(14);
+
const header = document.createElement('div');
header.className = 'es-inspector-entity-header';
header.innerHTML = `
<span class="es-entity-icon">${icons.box(16)}</span>
<input type="text" class="es-entity-name-input" value="${this.escapeHtml(name)}">
+ <span class="es-entity-visibility">${visibilityIcon}</span>
<span class="es-entity-id">ID:${entity}</span>
`;
@@ -331,48 +335,22 @@ export class InspectorPanel {
}
});
+ const visBtn = header.querySelector('.es-entity-visibility');
+ visBtn?.addEventListener('click', () => {
+ this.store_.toggleVisibility(entity as number);
+ });
+
this.contentContainer_.appendChild(header);
}
- private renderTagsSection(_entity: Entity): void {
- const section = document.createElement('div');
- section.className = 'es-component-section es-collapsible es-expanded';
- section.innerHTML = `
- <div class="es-component-header es-collapsible-header">
- <span class="es-collapse-icon">${icons.chevronDown(12)}</span>
- <span class="es-component-icon">${icons.check(14)}</span>
- <span class="es-component-title">Tags</span>
- <button class="es-btn es-btn-icon es-btn-remove">${icons.x(12)}</button>
- </div>
- <div class="es-component-properties es-collapsible-content">
- <div class="es-property-row">
- <label class="es-property-label">active</label>
- <div class="es-property-editor">
- <input type="checkbox" class="es-input-checkbox" checked>
- </div>
- </div>
- <div class="es-property-row">
- <label class="es-property-label">visible</label>
- <div class="es-property-editor">
- <input type="checkbox" class="es-input-checkbox" checked>
- </div>
- </div>
- <div class="es-property-row">
- <label class="es-property-label">static</label>
- <div class="es-property-editor">
- <input type="checkbox" class="es-input-checkbox">
- </div>
- </div>
- </div>
- `;
-
- const header = section.querySelector('.es-collapsible-header');
- header?.addEventListener('click', (e) => {
- if ((e.target as HTMLElement).closest('.es-btn-remove')) return;
- section.classList.toggle('es-expanded');
- });
-
- this.contentContainer_.appendChild(section);
+ private updateVisibilityIcon(): void {
+ const entityData = this.store_.getSelectedEntityData();
+ if (!entityData) return;
+ const visBtn = this.contentContainer_.querySelector('.es-entity-visibility');
+ if (visBtn) {
+ const isVisible = entityData.visible !== false;
+ visBtn.innerHTML = isVisible ? icons.eye(14) : icons.eyeOff(14);
+ }
}
private escapeHtml(text: string): string {
diff --git a/editor/src/panels/SceneViewPanel.ts b/editor/src/panels/SceneViewPanel.ts
index 28bdb687a..63547825c 100644
--- a/editor/src/panels/SceneViewPanel.ts
+++ b/editor/src/panels/SceneViewPanel.ts
@@ -53,6 +53,7 @@ export class SceneViewPanel {
private webglCanvas_: HTMLCanvasElement | null = null;
private overlayCanvas_: HTMLCanvasElement | null = null;
private unsubscribe_: (() => void) | null = null;
+ private unsubscribeFocus_: (() => void) | null = null;
private animationId_: number | null = null;
private continuousRender_ = false;
private resizeObserver_: ResizeObserver | null = null;
@@ -166,6 +167,7 @@ export class SceneViewPanel {
this.setupEvents();
this.unsubscribe_ = store.subscribe(() => this.onSceneChanged());
+ this.unsubscribeFocus_ = store.onFocusEntity((entityId) => this.focusOnEntity(entityId));
this.resize();
if (this.app_?.wasmModule) {
@@ -192,6 +194,10 @@ export class SceneViewPanel {
this.unsubscribe_();
this.unsubscribe_ = null;
}
+ if (this.unsubscribeFocus_) {
+ this.unsubscribeFocus_();
+ this.unsubscribeFocus_ = null;
+ }
if (this.resizeObserver_) {
this.resizeObserver_.disconnect();
this.resizeObserver_ = null;
@@ -489,7 +495,8 @@ export class SceneViewPanel {
const { worldX, worldY } = this.screenToWorld(e.clientX, e.clientY);
- if (this.gizmoManager_.getActiveId() !== 'select' && this.store_.selectedEntity !== null) {
+ if (this.gizmoManager_.getActiveId() !== 'select' && this.store_.selectedEntity !== null &&
+ this.store_.isEntityVisible(this.store_.selectedEntity as number)) {
this.updateGizmoContext();
if (this.gizmoManager_.onMouseDown(worldX, worldY)) {
this.startDocumentDrag();
@@ -600,6 +607,14 @@ export class SceneViewPanel {
this.store_.selectEntity(entity);
}
+ private focusOnEntity(entityId: number): void {
+ const worldTransform = this.store_.getWorldTransform(entityId);
+ this.panX_ = -worldTransform.position.x;
+ this.panY_ = worldTransform.position.y;
+ this.updateZoomDisplay();
+ this.requestRender();
+ }
+
private screenToWorld(clientX: number, clientY: number): { worldX: number; worldY: number } {
const rect = this.canvas_.getBoundingClientRect();
const dpr = window.devicePixelRatio || 1;
@@ -641,6 +656,8 @@ export class SceneViewPanel {
for (let i = scene.entities.length - 1; i >= 0; i--) {
const entity = scene.entities[i];
+ if (!this.store_.isEntityVisible(entity.id)) continue;
+
const transform = entity.components.find(c => c.type === 'LocalTransform');
if (!transform) continue;
@@ -745,7 +762,7 @@ export class SceneViewPanel {
const selectedEntity = this.store_.selectedEntity;
- if (selectedEntity !== null) {
+ if (selectedEntity !== null && this.store_.isEntityVisible(selectedEntity as number)) {
if (this.gizmoSettings_.showSelectionBox) {
this.drawSelectionBox(ctx);
}
@@ -879,10 +896,11 @@ export class SceneViewPanel {
const selectedEntity = this.store_.selectedEntity;
for (const entity of scene.entities) {
+ if (!this.store_.isEntityVisible(entity.id)) continue;
this.drawEntity(ctx, entity, entity.id === selectedEntity);
}
- if (selectedEntity !== null) {
+ if (selectedEntity !== null && this.store_.isEntityVisible(selectedEntity as number)) {
this.drawCameraFrustum(ctx);
if (this.gizmoManager_.getActiveId() !== 'select' && this.gizmoSettings_.showGizmos) {
diff --git a/editor/src/scene/EditorSceneManager.ts b/editor/src/scene/EditorSceneManager.ts
index b9daa1f79..41ef18806 100644
--- a/editor/src/scene/EditorSceneManager.ts
+++ b/editor/src/scene/EditorSceneManager.ts
@@ -109,6 +109,8 @@ export class EditorSceneManager {
const entity = this.world_.spawn();
this.entityMap_.set(entityData.id, entity);
+ if (entityData.visible === false) return;
+
for (const comp of entityData.components) {
await this.loadComponentWithEditorLogic(entity, comp, entityData.id);
}
@@ -196,6 +198,25 @@ export class EditorSceneManager {
}
}
+ // =========================================================================
+ // Visibility
+ // =========================================================================
+
+ hideEntity(entityId: number): void {
+ const entity = this.entityMap_.get(entityId);
+ if (entity === undefined) return;
+
+ if (this.world_.has(entity, Sprite)) {
+ this.world_.remove(entity, Sprite);
+ }
+ }
+
+ async showEntity(entityId: number): Promise<void> {
+ const entityData = this.entityDataMap_.get(entityId);
+ if (!entityData) return;
+ await this.updateEntity(entityId, entityData.components);
+ }
+
// =========================================================================
// Accessors
// =========================================================================
diff --git a/editor/src/store/EditorStore.ts b/editor/src/store/EditorStore.ts
index 1496c9d90..26bf7ed94 100644
--- a/editor/src/store/EditorStore.ts
+++ b/editor/src/store/EditorStore.ts
@@ -59,6 +59,13 @@ export interface HierarchyChangeEvent {
export type HierarchyChangeListener = (event: HierarchyChangeEvent) => void;
+export interface VisibilityChangeEvent {
+ entity: number;
+ visible: boolean;
+}
+
+export type VisibilityChangeListener = (event: VisibilityChangeEvent) => void;
+
// =============================================================================
// EditorStore
// =============================================================================
@@ -70,6 +77,7 @@ export class EditorStore {
private propertyListeners_: Set<PropertyChangeListener> = new Set();
private hierarchyListeners_: Set<HierarchyChangeListener> = new Set();
private focusListeners_: Set<(entityId: number) => void> = new Set();
+ private visibilityListeners_: Set<VisibilityChangeListener> = new Set();
private nextEntityId_ = 1;
private worldTransforms_ = new WorldTransformCache();
private entityMap_ = new Map<number, EntityData>();
@@ -200,6 +208,79 @@ export class EditorStore {
return () => this.focusListeners_.delete(listener);
}
+ // =========================================================================
+ // Visibility
+ // =========================================================================
+
+ toggleVisibility(entityId: number): void {
+ const entityData = this.entityMap_.get(entityId);
+ if (!entityData) return;
+
+ if (!entityData.visible) {
+ const parentId = entityData.parent;
+ if (parentId !== null) {
+ const parentData = this.entityMap_.get(parentId);
+ if (parentData && !parentData.visible) return;
+ }
+ this.showEntityTree(entityId);
+ } else {
+ this.hideEntityTree(entityId);
+ }
+ this.state_.isDirty = true;
+ this.notify();
+ }
+
+ isEntityVisible(entityId: number): boolean {
+ const entityData = this.entityMap_.get(entityId);
+ return entityData?.visible !== false;
+ }
+
+ isEntityDirectlyHidden(entityId: number): boolean {
+ const entityData = this.entityMap_.get(entityId);
+ if (!entityData || entityData.visible !== false) return false;
+ const parentId = entityData.parent;
+ if (parentId === null) return true;
+ const parentData = this.entityMap_.get(parentId);
+ return parentData?.visible !== false;
+ }
+
+ subscribeToVisibilityChanges(listener: VisibilityChangeListener): () => void {
+ this.visibilityListeners_.add(listener);
+ return () => this.visibilityListeners_.delete(listener);
+ }
+
+ private hideEntityTree(entityId: number): void {
+ const entityData = this.entityMap_.get(entityId);
+ if (!entityData) return;
+ entityData.visible = false;
+ this.notifyVisibilityChange({ entity: entityId, visible: false });
+ for (const childId of entityData.children) {
+ const childData = this.entityMap_.get(childId);
+ if (childData && childData.visible !== false) {
+ this.hideEntityTree(childId);
+ }
+ }
+ }
+
+ private showEntityTree(entityId: number): void {
+ const entityData = this.entityMap_.get(entityId);
+ if (!entityData) return;
+ entityData.visible = true;
+ this.notifyVisibilityChange({ entity: entityId, visible: true });
+ for (const childId of entityData.children) {
+ const childData = this.entityMap_.get(childId);
+ if (childData && childData.visible === false) {
+ this.showEntityTree(childId);
+ }
+ }
+ }
+
+ private notifyVisibilityChange(event: VisibilityChangeEvent): void {
+ for (const listener of this.visibilityListeners_) {
+ listener(event);
+ }
+ }
+
// =========================================================================
// Entity Operations
// =========================================================================
@@ -216,6 +297,19 @@ export class EditorStore {
);
this.executeCommand(cmd);
+ if (parent !== null) {
+ const parentData = this.entityMap_.get(parent as number);
+ if (parentData && !parentData.visible) {
+ const newEntityData = this.entityMap_.get(id);
+ if (newEntityData) {
+ newEntityData.visible = false;
+ this.notifyVisibilityChange({ entity: id, visible: false });
+ }
+ }
+ }
+
+ this.selectEntity(id as Entity);
+
return id as Entity;
}
diff --git a/editor/src/styles/editor.css b/editor/src/styles/editor.css
index 67727ec66..888821525 100644
--- a/editor/src/styles/editor.css
+++ b/editor/src/styles/editor.css
@@ -371,14 +371,17 @@ svg {
.es-hierarchy-item {
user-select: none;
+ position: relative;
}
.es-hierarchy-row {
display: flex;
align-items: center;
padding: 3px 8px;
+ min-width: fit-content;
cursor: pointer;
border-left: 2px solid transparent;
+ position: relative;
}
.es-hierarchy-row:hover {
@@ -405,8 +408,40 @@ svg {
outline-offset: -2px;
}
+.es-hierarchy-item.es-drop-before > .es-hierarchy-row::before {
+ content: '';
+ position: absolute;
+ top: 0;
+ left: 20px;
+ right: 0;
+ height: 2px;
+ background: #61afef;
+ pointer-events: none;
+}
+
+.es-hierarchy-item.es-drop-after > .es-hierarchy-row::after {
+ content: '';
+ position: absolute;
+ bottom: 0;
+ left: 20px;
+ right: 0;
+ height: 2px;
+ background: #61afef;
+ pointer-events: none;
+}
+
+.es-hierarchy-item.es-drop-inside > .es-hierarchy-row {
+ background: rgba(97, 175, 239, 0.3);
+ border-left-color: #61afef;
+}
+
+.es-hierarchy-item.es-dragging {
+ opacity: 0.5;
+}
+
.es-hierarchy-visibility {
width: 16px;
+ flex-shrink: 0;
display: inline-flex;
align-items: center;
justify-content: center;
@@ -419,6 +454,7 @@ svg {
.es-hierarchy-expand {
width: 16px;
+ flex-shrink: 0;
display: inline-flex;
align-items: center;
justify-content: center;
@@ -435,10 +471,12 @@ svg {
.es-hierarchy-spacer {
width: 16px;
+ flex-shrink: 0;
}
.es-hierarchy-icon {
width: 18px;
+ flex-shrink: 0;
display: inline-flex;
align-items: center;
justify-content: center;
@@ -451,6 +489,7 @@ svg {
.es-hierarchy-name {
flex: 1;
+ min-width: 80px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
@@ -459,6 +498,7 @@ svg {
.es-hierarchy-type {
width: 60px;
+ flex-shrink: 0;
text-align: right;
font-size: 11px;
color: var(--es-text-secondary);
@@ -466,13 +506,42 @@ svg {
.es-hierarchy-children {
display: none;
- padding-left: 16px;
+ position: relative;
}
.es-hierarchy-item.es-expanded > .es-hierarchy-children {
display: block;
}
+.es-hierarchy-children > .es-hierarchy-item::before {
+ content: '';
+ position: absolute;
+ top: 0;
+ left: calc(2px + var(--depth) * 16px);
+ bottom: 0;
+ border-left: 1px dotted var(--es-border);
+ pointer-events: none;
+}
+
+.es-hierarchy-children > .es-hierarchy-item:last-child::before {
+ bottom: auto;
+ height: 11px;
+}
+
+.es-hierarchy-children > .es-hierarchy-item::after {
+ content: '';
+ position: absolute;
+ top: 11px;
+ left: calc(2px + var(--depth) * 16px);
+ width: 8px;
+ border-top: 1px dotted var(--es-border);
+ pointer-events: none;
+}
+
+.es-hierarchy-item.es-entity-hidden > .es-hierarchy-row {
+ opacity: 0.4;
+}
+
.es-hierarchy-footer {
padding: 6px 12px;
font-size: 11px;
@@ -540,6 +609,23 @@ svg {
color: #d19a66;
}
+.es-entity-visibility {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ cursor: pointer;
+ padding: 2px;
+ border-radius: 3px;
+}
+
+.es-entity-visibility:hover {
+ background: var(--es-bg-hover);
+}
+
+.es-entity-visibility svg {
+ stroke: var(--es-text-secondary);
+}
+
.es-entity-id {
font-size: 10px;
color: var(--es-text-secondary);
diff --git a/editor/src/sync/RuntimeSyncService.ts b/editor/src/sync/RuntimeSyncService.ts
index cae8a564d..2fa1ef222 100644
--- a/editor/src/sync/RuntimeSyncService.ts
+++ b/editor/src/sync/RuntimeSyncService.ts
@@ -3,7 +3,7 @@
* @brief Syncs editor state changes to runtime rendering
*/
-import type { EditorStore, PropertyChangeEvent, HierarchyChangeEvent } from '../store/EditorStore';
+import type { EditorStore, PropertyChangeEvent, HierarchyChangeEvent, VisibilityChangeEvent } from '../store/EditorStore';
import type { EditorSceneManager } from '../scene/EditorSceneManager';
import { getAssetEventBus, type AssetEvent } from '../events/AssetEventBus';
import { getDependencyGraph } from '../asset/AssetDependencyGraph';
@@ -32,6 +32,12 @@ export class RuntimeSyncService {
})
);
+ this.unsubscribes_.push(
+ this.store_.subscribeToVisibilityChanges((event) => {
+ this.onVisibilityChange(event);
+ })
+ );
+
this.unsubscribes_.push(
getAssetEventBus().on('material', (event) => {
if (event.type === 'asset:modified') {
@@ -49,6 +55,14 @@ export class RuntimeSyncService {
);
}
+ private onVisibilityChange(event: VisibilityChangeEvent): void {
+ if (event.visible) {
+ this.sceneManager_.showEntity(event.entity);
+ } else {
+ this.sceneManager_.hideEntity(event.entity);
+ }
+ }
+
private onPropertyChange(event: PropertyChangeEvent): void {
this.scheduleEntityUpdate(event.entity);
}
@@ -86,10 +100,10 @@ export class RuntimeSyncService {
}
private async syncEntity(entityId: number): Promise<void> {
+ if (!this.store_.isEntityVisible(entityId)) return;
const entityData = this.store_.getEntityData(entityId);
- if (entityData) {
- await this.sceneManager_.updateEntity(entityId, entityData.components);
- }
+ if (!entityData) return;
+ await this.sceneManager_.updateEntity(entityId, entityData.components);
}
dispose(): void {
diff --git a/editor/src/types/SceneTypes.ts b/editor/src/types/SceneTypes.ts
index 8f2ec5ae7..4e0620105 100644
--- a/editor/src/types/SceneTypes.ts
+++ b/editor/src/types/SceneTypes.ts
@@ -23,6 +23,7 @@ export interface EntityData {
parent: number | null;
children: number[];
components: ComponentData[];
+ visible: boolean;
}
export interface ComponentData {
@@ -70,5 +71,6 @@ export function createEntityData(
parent,
children: [],
components: [],
+ visible: true,
};
}
diff --git a/editor/src/utils/icons.ts b/editor/src/utils/icons.ts
index 2c4415859..c0230f0c6 100644
--- a/editor/src/utils/icons.ts
+++ b/editor/src/utils/icons.ts
@@ -49,6 +49,7 @@ import {
Download,
LayoutTemplate,
Bone,
+ EyeOff,
} from 'lucide';
// =============================================================================
@@ -106,6 +107,7 @@ export const icons = {
copy: (size?: number) => renderIcon(Copy as IconNode, size),
settings: (size?: number) => renderIcon(Settings as IconNode, size),
eye: (size?: number) => renderIcon(Eye as IconNode, size),
+ eyeOff: (size?: number) => renderIcon(EyeOff as IconNode, size),
star: (size?: number) => renderIcon(Star as IconNode, size),
chevronRight: (size?: number) => renderIcon(ChevronRight as IconNode, size),
chevronDown: (size?: number) => renderIcon(ChevronDown as IconNode, size),