* @zh 移除指定的组件 * @en Remove specified component * * @param component - @zh 要移除的组件实例 @en Component instance to remove
(component: Component)
| 621 | * @param component - @zh 要移除的组件实例 @en Component instance to remove |
| 622 | */ |
| 623 | public removeComponent(component: Component): void { |
| 624 | const componentType = component.constructor as ComponentType; |
| 625 | const registry = this.scene?.componentRegistry ?? GlobalComponentRegistry; |
| 626 | |
| 627 | if (!registry.isRegistered(componentType)) { |
| 628 | return; |
| 629 | } |
| 630 | |
| 631 | const bitIndex = registry.getBitIndex(componentType); |
| 632 | BitMask64Utils.clearBit(this._componentMask, bitIndex); |
| 633 | this._componentCache = null; |
| 634 | |
| 635 | this.scene?.componentStorageManager?.removeComponent(this.id, componentType); |
| 636 | this.scene?.referenceTracker?.clearComponentReferences(component); |
| 637 | |
| 638 | component.onRemovedFromEntity?.(); |
| 639 | component.entityId = null; |
| 640 | |
| 641 | if (this.scene?.eventSystem) { |
| 642 | this.scene.eventSystem.emitSync('component:removed', { |
| 643 | timestamp: Date.now(), |
| 644 | source: 'Entity', |
| 645 | entityId: this.id, |
| 646 | entityName: this.name, |
| 647 | entityTag: this.tag?.toString(), |
| 648 | componentType: getComponentTypeName(componentType), |
| 649 | component: component |
| 650 | }); |
| 651 | } |
| 652 | |
| 653 | this.notifyQuerySystems(componentType); |
| 654 | } |
| 655 | |
| 656 | /** |
| 657 | * @zh 移除指定类型的组件 |
no test coverage detected