新增 tryGetComponent 方法

This commit is contained in:
yhh
2021-03-26 12:53:09 +08:00
parent b9522ade5d
commit d2915fe30c
4 changed files with 30 additions and 2 deletions

View File

@@ -405,10 +405,21 @@ module es {
* 获取类型T的第一个组件并返回它。如果没有找到组件则返回null。
* @param type
*/
public getComponent<T extends Component>(type): T {
public getComponent<T extends Component>(type: any): T {
return this.components.getComponent(type, false);
}
/**
* 尝试获取T类型的组件。如果未找到任何组件则返回false
* @param type
* @param outComponent
* @returns
*/
public tryGetComponent<T extends Component>(type: any, outComponent: Ref<T>): boolean {
outComponent.value = this.components.getComponent<T>(type, false);
return outComponent.value != null;
}
/**
* 检查实体是否具有该组件
* @param type