import { IStringDictionary, Undefinable } from "../utils/types"; import { Asset } from "./asset"; import { Entity, IRunEvent } from "./entity"; import { Thing } from "./thing"; export interface IComponent extends IRunEvent { isSingle: boolean; ioe: number;// index of Entity 在实体组件数组中的位置 entity: Undefinable; nextStep: Function; update: (entity: Entity) => any; } export interface IComponentOption { entity?: Entity; type?: string; isSingle?: boolean; accessors?: IStringDictionary | string[] } export abstract class Component extends Thing implements IComponent { entity: Undefinable; //最终生成的目标对象 protected _object: any; /** * 此属性是否将资源的属性在组件中解释 * 比如材质是false 那么材质的属性指点点击关联的材质,才会显示材质的相应属性 * 而相机为true ,就是在属性面板直接显示资源的属性在inspector */ inspectorAsset: boolean = true; /** * 关联的资源 */ _asset: Undefinable | Asset[]; /** * 是否只允许存在一个 */ isSingle: boolean = false; /** * Index of Entity 在实体组件数组中的位置 */ ioe: number = -1; label: string = '组件'; //显示到设备的最终名字 constructor(protected options?: IComponentOption) { super(); this.entity = options?.entity; this.isSingle = options?.isSingle || false; this.init(); } init() { } set needsUpdate(v: boolean) { if (v !== this._needsUpdate && this.entity && v) this.entity.needsUpdate = v } get object() { return this._object; } set object(val: any) { this._object = val; } beforeupdate() { } afterupdate() { } nextStep(entity: Entity) { if (!this._needsUpdate) return; this.afterupdate() //存在更新 this.update(entity); this._needsUpdate = false; this.beforeupdate(); } update(option?: any): any { } }