新增基础实体系统

This commit is contained in:
yhh
2020-06-08 18:26:05 +08:00
parent 7939253622
commit 57efc5b0e6
18 changed files with 551 additions and 28 deletions

View File

@@ -7,6 +7,23 @@ class Entity {
/** 当前附加到此实体的所有组件的列表 */
public readonly components: Component[];
private _updateOrder: number = 0;
private _enabled: boolean = true;
public get enabled(){
return this._enabled;
}
public set enabled(value: boolean){
this.setEnabled(value);
}
public setEnabled(isEnabled: boolean){
if (this._enabled != isEnabled){
this._enabled = isEnabled;
}
return this;
}
constructor(name: string){
this.name = name;
@@ -49,6 +66,10 @@ class Entity {
return component;
}
public getComponent<T extends Component>(): T{
return this.components.firstOrDefault(component => component instanceof Component) as T;
}
public update(){
this.components.forEach(component => component.update());
this.transform.updateTransform();