MCPcopy Create free account
hub / github.com/esengine/esengine / setMode

Method setMode

packages/runtime-core/src/GameRuntime.ts:274–321  ·  view source on GitHub ↗

* @zh 设置运行模式 * @en Set runtime mode * * @zh 根据模式自动配置系统启用状态、UI 显示等 * @en Automatically configures system enabling, UI visibility, etc. based on mode * * @param mode - @zh 目标模式 @en Target mode * @param options - @zh 可选覆盖配置 @en Optional override configuration

(mode: RuntimeMode, options?: Partial<RuntimeModeConfig>)

Source from the content-addressed store, hash-verified

272 * @param options - @zh 可选覆盖配置 @en Optional override configuration
273 */
274 setMode(mode: RuntimeMode, options?: Partial<RuntimeModeConfig>): void {
275 if (!this._state.initialized) {
276 console.warn('[GameRuntime] Cannot set mode before initialization');
277 return;
278 }
279
280 const previousMode = this._state.mode;
281 this._state.mode = mode;
282
283 // 获取模式配置并应用覆盖
284 const config = { ...getRuntimeModeConfig(mode), ...options };
285
286 console.log(`[GameRuntime] Mode: ${previousMode} → ${mode}`);
287
288 // 1. 配置场景编辑器模式
289 if (this._scene) {
290 this._scene.isEditorMode = !config.triggerLifecycle;
291 }
292
293 // 2. 配置渲染系统
294 if (this._renderSystem) {
295 this._renderSystem.setPreviewMode(mode !== RuntimeMode.EditorStatic);
296 this._renderSystem.setShowGizmos(config.showGizmos);
297 }
298
299 // 3. 配置引擎桥接
300 if (this._bridge) {
301 this._bridge.setShowGrid(config.showGrid);
302 this._bridge.setEditorMode(config.isEditorEnvironment);
303 }
304
305 // 4. 配置输入系统
306 if (this._inputSystem) {
307 this._inputSystem.enabled = config.enableInput;
308 }
309
310 // 5. 配置游戏逻辑系统
311 this._applySystemConfig(config);
312
313 // 6. 触发生命周期(从静态模式进入其他模式时)
314 if (previousMode === RuntimeMode.EditorStatic && config.triggerLifecycle) {
315 this._scene?.begin();
316 }
317
318 // 7. 更新运行状态
319 this._state.running = shouldEnableGameLogic(mode);
320 this._state.paused = false;
321 }
322
323 /**
324 * @zh 应用系统配置

Callers 2

startMethod · 0.95
stopMethod · 0.95

Calls 10

_applySystemConfigMethod · 0.95
getRuntimeModeConfigFunction · 0.90
shouldEnableGameLogicFunction · 0.90
setShowGizmosMethod · 0.65
setShowGridMethod · 0.65
warnMethod · 0.45
logMethod · 0.45
setPreviewModeMethod · 0.45
setEditorModeMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected