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.

feat: add live preview toggle to scene view settings

esengine438f86a84938
diff --git a/editor/src/panels/scene-view/GizmoToolbar.ts b/editor/src/panels/scene-view/GizmoToolbar.ts
index 7b985a2f1..226ba85f7 100644
--- a/editor/src/panels/scene-view/GizmoToolbar.ts
+++ b/editor/src/panels/scene-view/GizmoToolbar.ts
@@ -74,6 +74,13 @@ export class GizmoToolbar {
<span>Show Stats</span>
</label>
</div>
+ <div class="es-settings-divider"></div>
+ <div class="es-settings-row">
+ <label class="es-settings-checkbox">
+ <input type="checkbox" data-setting="scene.livePreview" ${getSettingsValue<boolean>('scene.livePreview') ? 'checked' : ''}>
+ <span>Live Preview</span>
+ </label>
+ </div>
</div>
</div>`;
}
diff --git a/editor/src/panels/scene-view/SceneViewPanel.ts b/editor/src/panels/scene-view/SceneViewPanel.ts
index 02c4eef60..115d1a7aa 100644
--- a/editor/src/panels/scene-view/SceneViewPanel.ts
+++ b/editor/src/panels/scene-view/SceneViewPanel.ts
@@ -12,7 +12,7 @@ import { getEntityBounds } from '../../bounds';
import { GizmoManager } from '../../gizmos';
import type { GizmoContext } from '../../gizmos';
import { ColliderOverlay } from '../../gizmos/ColliderOverlay';
-import { getSettingsValue } from '../../settings/SettingsRegistry';
+import { getSettingsValue, onSettingsChange } from '../../settings/SettingsRegistry';
import type { EntityData } from '../../types/SceneTypes';
import { CameraController } from './CameraController';
@@ -43,8 +43,10 @@ export class SceneViewPanel {
private unsubscribe_: (() => void) | null = null;
private unsubscribeSceneSync_: (() => void) | null = null;
private unsubscribeFocus_: (() => void) | null = null;
+ private unsubscribeLivePreview_: (() => void) | null = null;
private animationId_: number | null = null;
private continuousRender_ = false;
+ private livePreview_ = false;
private isDirty_ = true;
private resizeObserver_: ResizeObserver | null = null;
private projectPath_: string | null = null;
@@ -138,6 +140,14 @@ export class SceneViewPanel {
this.toolbar_.updateZoomDisplay(this.camera_.zoom);
});
+ this.livePreview_ = getSettingsValue<boolean>('scene.livePreview') ?? false;
+ this.unsubscribeLivePreview_ = onSettingsChange((id, value) => {
+ if (id === 'scene.livePreview') {
+ this.livePreview_ = value as boolean;
+ if (this.livePreview_) this.requestRender();
+ }
+ });
+
const viewport = this.container_.querySelector('.es-sceneview-viewport');
if (viewport) {
this.resizeObserver_ = new ResizeObserver(() => this.resize());
@@ -255,6 +265,10 @@ export class SceneViewPanel {
this.unsubscribeFocus_();
this.unsubscribeFocus_ = null;
}
+ if (this.unsubscribeLivePreview_) {
+ this.unsubscribeLivePreview_();
+ this.unsubscribeLivePreview_ = null;
+ }
if (this.resizeObserver_) {
this.resizeObserver_.disconnect();
this.resizeObserver_ = null;
@@ -509,6 +523,7 @@ export class SceneViewPanel {
if (this.animationId_ !== null) return;
this.animationId_ = requestAnimationFrame(() => {
this.animationId_ = null;
+ if (this.livePreview_) this.isDirty_ = true;
if (this.isDirty_) {
this.isDirty_ = false;
try {