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

Method addComponents

packages/core/src/ECS/Entity.ts:697–709  ·  view source on GitHub ↗

* @zh 批量添加组件 * @en Add multiple components * * @param components - @zh 要添加的组件数组 @en Array of components to add * @returns @zh 添加的组件数组 @en Array of added components

(components: T[])

Source from the content-addressed store, hash-verified

695 * @returns @zh 添加的组件数组 @en Array of added components
696 */
697 public addComponents<T extends Component>(components: T[]): T[] {
698 const addedComponents: T[] = [];
699
700 for (const component of components) {
701 try {
702 addedComponents.push(this.addComponent(component));
703 } catch (error) {
704 Entity._logger.warn(`添加组件失败 ${getComponentInstanceTypeName(component)}:`, error);
705 }
706 }
707
708 return addedComponents;
709 }
710
711 /**
712 * 批量移除组件类型

Callers 1

Entity.test.tsFile · 0.45

Calls 4

addComponentMethod · 0.95
pushMethod · 0.65
warnMethod · 0.45

Tested by

no test coverage detected