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

Method hasComponent

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

* @zh 检查实体是否拥有指定类型的组件 * @en Check if entity has component of specified type * * @param type - @zh 组件类型构造函数 @en Component type constructor * @returns @zh 如果实体拥有该组件返回true @en Returns true if entity has the component * * @example * ```typescript * if (entity.hasC

(type: ComponentType<T>)

Source from the content-addressed store, hash-verified

545 * ```
546 */
547 public hasComponent<T extends Component>(type: ComponentType<T>): boolean {
548 const registry = this.scene?.componentRegistry ?? GlobalComponentRegistry;
549 if (!registry.isRegistered(type)) {
550 return false;
551 }
552
553 const mask = registry.getBitMask(type);
554 return BitMask64Utils.hasAny(this._componentMask, mask);
555 }
556
557 /**
558 * @zh 获取或创建指定类型的组件

Callers 7

addComponentMethod · 0.95
getComponentMethod · 0.95
processMethod · 0.45
EntityInspectorFunction · 0.45
EntityInspectorPanelFunction · 0.45
hasComponentsFunction · 0.45
hasAnyComponentFunction · 0.45

Calls 3

isRegisteredMethod · 0.45
getBitMaskMethod · 0.45
hasAnyMethod · 0.45

Tested by

no test coverage detected