新增 tryGetComponent 方法
This commit is contained in:
7
source/bin/framework.d.ts
vendored
7
source/bin/framework.d.ts
vendored
@@ -364,6 +364,13 @@ declare module es {
|
|||||||
* @param type
|
* @param type
|
||||||
*/
|
*/
|
||||||
getComponent<T extends Component>(type: any): T;
|
getComponent<T extends Component>(type: any): T;
|
||||||
|
/**
|
||||||
|
* 尝试获取T类型的组件。如果未找到任何组件,则返回false
|
||||||
|
* @param type
|
||||||
|
* @param outComponent
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
tryGetComponent<T extends Component>(type: any, outComponent: Ref<T>): boolean;
|
||||||
/**
|
/**
|
||||||
* 检查实体是否具有该组件
|
* 检查实体是否具有该组件
|
||||||
* @param type
|
* @param type
|
||||||
|
|||||||
@@ -941,6 +941,16 @@ var es;
|
|||||||
Entity.prototype.getComponent = function (type) {
|
Entity.prototype.getComponent = function (type) {
|
||||||
return this.components.getComponent(type, false);
|
return this.components.getComponent(type, false);
|
||||||
};
|
};
|
||||||
|
/**
|
||||||
|
* 尝试获取T类型的组件。如果未找到任何组件,则返回false
|
||||||
|
* @param type
|
||||||
|
* @param outComponent
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
Entity.prototype.tryGetComponent = function (type, outComponent) {
|
||||||
|
outComponent.value = this.components.getComponent(type, false);
|
||||||
|
return outComponent.value != null;
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
* 检查实体是否具有该组件
|
* 检查实体是否具有该组件
|
||||||
* @param type
|
* @param type
|
||||||
|
|||||||
2
source/bin/framework.min.js
vendored
2
source/bin/framework.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -405,10 +405,21 @@ module es {
|
|||||||
* 获取类型T的第一个组件并返回它。如果没有找到组件,则返回null。
|
* 获取类型T的第一个组件并返回它。如果没有找到组件,则返回null。
|
||||||
* @param type
|
* @param type
|
||||||
*/
|
*/
|
||||||
public getComponent<T extends Component>(type): T {
|
public getComponent<T extends Component>(type: any): T {
|
||||||
return this.components.getComponent(type, false);
|
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
|
* @param type
|
||||||
|
|||||||
Reference in New Issue
Block a user