getComponent不再需要指定类型

This commit is contained in:
yhh
2021-03-29 17:28:58 +08:00
parent 6b2c18ad75
commit e6096b644f
5 changed files with 10 additions and 10 deletions

View File

@@ -384,7 +384,7 @@ module es {
* 创建组件的新实例。返回实例组件
* @param componentType
*/
public createComponent<T extends Component>(componentType: new () => T): T {
public createComponent<T extends Component>(componentType: new (...args) => T): T {
let component = new componentType();
this.addComponent(component);
return component;
@@ -405,7 +405,7 @@ module es {
* 获取类型T的第一个组件并返回它。如果没有找到组件则返回null。
* @param type
*/
public getComponent<T extends Component>(type: any): T {
public getComponent<T extends Component>(type: new (...args) => T): T {
return this.components.getComponent(type, false);
}
@@ -415,7 +415,7 @@ module es {
* @param outComponent
* @returns
*/
public tryGetComponent<T extends Component>(type: any, outComponent: Ref<T>): boolean {
public tryGetComponent<T extends Component>(type: new (...args) => T, outComponent: Ref<T>): boolean {
outComponent.value = this.components.getComponent<T>(type, false);
return outComponent.value != null;
}