新增基础实体系统
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user