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;
|
2020-06-09 11:09:26 +08:00
|
|
|
public updateInterval: number = 1;
|
2020-07-03 16:45:52 +08:00
|
|
|
/** 允许用户为实体存入信息 */
|
|
|
|
|
public userData: any;
|
2020-06-09 11:09:26 +08:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-09 14:16:10 +08:00
|
|
|
public get localPosition(){
|
|
|
|
|
return new Vector2(this.entity.x + this.x, this.entity.y + this.y);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-08 18:26:05 +08:00
|
|
|
public setEnabled(isEnabled: boolean){
|
|
|
|
|
if (this._enabled != isEnabled){
|
|
|
|
|
this._enabled = isEnabled;
|
2020-06-09 11:09:26 +08:00
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2020-06-16 11:22:37 +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(){
|
2020-06-08 21:53:09 +08:00
|
|
|
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));
|
2020-06-08 21:53:09 +08:00
|
|
|
this.entity.scene.entityProcessors.onComponentRemoved(this.entity);
|
2020-06-08 20:11:58 +08:00
|
|
|
}
|
2020-06-08 16:23:48 +08:00
|
|
|
}
|