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

Method createComponent

packages/fairygui/src/ecs/FGUIComponent.ts:295–331  ·  view source on GitHub ↗

* Create component from loaded package * 从已加载的包创建组件 * * Note: Disposes existing component before creating new one to avoid visual overlap * 注意:创建新组件前会先销毁已有组件,避免视觉叠加

(componentName?: string)

Source from the content-addressed store, hash-verified

293 * 注意:创建新组件前会先销毁已有组件,避免视觉叠加
294 */
295 public createComponent(componentName?: string): GObject | null {
296 const name = componentName || this.componentName;
297 if (!this._package) {
298 return null;
299 }
300 if (!name) {
301 return null;
302 }
303
304 // Dispose existing component before creating new one
305 // 创建新组件前先销毁已有组件
306 if (this._component) {
307 if (this._root) {
308 this._root.removeChild(this._component);
309 }
310 this._component.dispose();
311 this._component = null;
312 }
313
314 try {
315 this._component = this._package.createObject(name);
316
317 if (this._component && this._root) {
318 this.syncProperties();
319 this._root.addChild(this._component);
320 }
321
322 this._version++;
323 this._onStateChange?.('updated');
324 return this._component;
325 } catch (e) {
326 // Log full error with stack trace for debugging
327 console.error(`[FGUIComponent] Error creating component "${name}":`, e);
328 this._error = e instanceof Error ? e.message : String(e);
329 return null;
330 }
331 }
332
333 /**
334 * Get child by name from the component

Callers 2

_needsReloadMethod · 0.45
_doLoadMethod · 0.45

Calls 6

syncPropertiesMethod · 0.95
disposeMethod · 0.65
removeChildMethod · 0.45
createObjectMethod · 0.45
addChildMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected