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

Method createScene

packages/core/src/ECS/World.ts:173–203  ·  view source on GitHub ↗

* @zh 创建并添加Scene到World * @en Create and add Scene to World * * @param sceneName - @zh Scene名称 @en Scene name * @param sceneInstance - @zh Scene实例(可选)@en Scene instance (optional) * @returns @zh 创建的Scene实例 @en Created Scene instance

(sceneName: string, sceneInstance?: T)

Source from the content-addressed store, hash-verified

171 * @returns @zh 创建的Scene实例 @en Created Scene instance
172 */
173 public createScene<T extends IScene>(sceneName: string, sceneInstance?: T): T {
174 if (!sceneName || typeof sceneName !== 'string' || sceneName.trim() === '') {
175 throw new Error('Scene name不能为空');
176 }
177
178 if (this._scenes.has(sceneName)) {
179 throw new Error(`Scene name '${sceneName}' 已存在于World '${this.name}' 中`);
180 }
181
182 if (this._scenes.size >= this._config.maxScenes!) {
183 throw new Error(`World '${this.name}' 已达到最大Scene数量限制: ${this._config.maxScenes}`);
184 }
185
186 const scene = sceneInstance || (new Scene() as unknown as T);
187
188 if (this._config.debug) {
189 const performanceMonitor = new PerformanceMonitor();
190 performanceMonitor.enable();
191 scene.services.registerInstance(PerformanceMonitor, performanceMonitor);
192 }
193
194 (scene as { id?: string }).id = sceneName;
195 if (!scene.name) {
196 scene.name = sceneName;
197 }
198
199 this._scenes.set(sceneName, scene);
200 scene.initialize();
201
202 return scene;
203 }
204
205 /**
206 * @zh 移除Scene

Callers 6

setSceneMethod · 0.45
World.test.tsFile · 0.45
constructorMethod · 0.45

Calls 5

enableMethod · 0.95
hasMethod · 0.65
setMethod · 0.65
initializeMethod · 0.65
registerInstanceMethod · 0.45

Tested by

no test coverage detected