Unit.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import BasicObject from "../../Engine/Basic/BasicObject";
  2. import EventManager from "../../Engine/Event/EventManager";
  3. import Tool from "../../Engine/Tool/Tool";
  4. import { _EUnitType, _ICreateUnit } from "../Game/Data/Unit/UnitConfig";
  5. import GameEventName from "../Event/GameEventName";
  6. /**
  7. * 实体单元
  8. * @param 设计目的 规范实体单元的拓展,便于修改、维护
  9. * @param 可能问题 任意拓展后,出现难以预计的情况
  10. */
  11. export default abstract class Unit extends BasicObject {
  12. public _createUnit: _ICreateUnit;
  13. constructor (createUnit: _ICreateUnit) {
  14. super();
  15. this._createUnit = createUnit;
  16. // 替换唯一ID
  17. if (this._createUnit.unitID != null) {
  18. this._id = this._createUnit.unitID;
  19. }
  20. this.createNode();
  21. this.createComponents();
  22. Tool.log(this);
  23. EventManager.sendEvent(GameEventName.Unit.Unit_CreateUnitComplete, this);
  24. }
  25. /**获得创建数据 */
  26. public get createUnit (): Readonly<_ICreateUnit> {
  27. return this._createUnit;
  28. }
  29. /**获得节点 */
  30. public abstract get fgui (): fgui.GComponent;
  31. /**获得类型 */
  32. public abstract get type (): _EUnitType;
  33. /**创建节点 */
  34. protected abstract createNode (): void;
  35. /**创建组件 */
  36. protected abstract createComponents (): void;
  37. }