Unit.ts 1.6 KB

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