Files
esengine/source/src/ECS/Component.ts

75 lines
1.7 KiB
TypeScript
Raw Normal View History

2020-06-29 15:41:02 +08:00
abstract class Component extends egret.DisplayObjectContainer {
2020-06-08 16:23:48 +08:00
public entity: Entity;
2020-06-08 18:26:05 +08:00
private _enabled: boolean = true;
public updateInterval: number = 1;
2020-07-03 16:45:52 +08:00
/** 允许用户为实体存入信息 */
public userData: any;
2020-06-08 18:26:05 +08:00
public get enabled(){
return this.entity ? this.entity.enabled && this._enabled : this._enabled;
}
public set enabled(value: boolean){
this.setEnabled(value);
}
public setEnabled(isEnabled: boolean){
if (this._enabled != isEnabled){
this._enabled = isEnabled;
if (this._enabled){
this.onEnabled();
}else{
this.onDisabled();
}
2020-06-08 18:26:05 +08:00
}
return this;
}
2020-06-08 16:23:48 +08:00
2020-06-16 00:04:28 +08:00
public initialize(){
}
2020-06-08 16:23:48 +08:00
2020-06-08 23:04:57 +08:00
public onAddedToEntity(){
}
public onRemovedFromEntity(){
}
public onEnabled(){
}
public onDisabled(){
}
2020-06-08 16:23:48 +08:00
public update(){
2020-06-08 18:26:05 +08:00
2020-06-08 16:23:48 +08:00
}
public debugRender(){
}
2020-07-08 18:12:17 +08:00
/**
*
* @param comp
*/
public onEntityTransformChanged(comp: TransformComponent){
}
2020-06-08 20:11:58 +08:00
/** 内部使用 运行时不应该调用 */
public registerComponent(){
this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this), false);
this.entity.scene.entityProcessors.onComponentAdded(this.entity);
}
public deregisterComponent(){
2020-06-08 20:11:58 +08:00
this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this));
this.entity.scene.entityProcessors.onComponentRemoved(this.entity);
2020-06-08 20:11:58 +08:00
}
2020-06-08 16:23:48 +08:00
}