AddCellOperation.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { v3 } from "cc";
  2. import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
  3. import { Checkpoint } from "../Checkpoint";
  4. import { CheckpointModelComp } from "../model/CheckpointModel";
  5. import { CheckpointViewComp } from "../view/CheckpointViewComp";
  6. import { Station } from "../../station/Station";
  7. /**
  8. * 添加两格
  9. */
  10. @ecs.register('AddCellOperation')
  11. export class AddCellOperationComp extends ecs.Comp {
  12. reset() {
  13. }
  14. }
  15. export class AddCellOperationSystem extends ecs.ComblockSystem implements ecs.IEntityEnterSystem {
  16. filter(): ecs.IMatcher {
  17. return ecs.allOf(CheckpointModelComp, AddCellOperationComp);
  18. }
  19. entityEnter(e: Checkpoint): void {
  20. this.createStation(e, 2)
  21. e.remove(AddCellOperationComp)
  22. }
  23. createStation(e: Checkpoint, count: number) {
  24. const checkpoint_root = e.get(CheckpointViewComp).node
  25. const checkpoint_model = e.get(CheckpointModelComp)
  26. const start_point = v3(-1.2, 0, 1.2)
  27. for (let index = 0; index < count; index++) {
  28. const station = ecs.getEntity<Station>(Station);
  29. // 添加关卡到场景
  30. const h_index = checkpoint_model.stations.length >= 5 ? checkpoint_model.stations.length - 5 : (checkpoint_model.stations.length) % 5
  31. // const v_index = Math.floor((checkpoint_model.stations.length + index) / 5)
  32. const v_index = checkpoint_model.stations.length >= 5 ? 1 : 0
  33. checkpoint_model.stations.push(station)
  34. station.load(checkpoint_root, v3(start_point.x + h_index * 0.5, 0, start_point.z + v_index * 0.5));
  35. e.addChild(station)
  36. }
  37. }
  38. }