OutArea.ts 957 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { _decorator, Component, Node } from 'cc';
  2. const { ccclass, property, executeInEditMode } = _decorator;
  3. @ccclass('OutArea')
  4. @executeInEditMode
  5. export class OutArea extends Component {
  6. @property(Node)
  7. outNodes: Node = null!;
  8. // 直接使用outNodes的子节点管理
  9. get cups() {
  10. return this.outNodes.children;
  11. }
  12. start() {
  13. }
  14. update(deltaTime: number) {
  15. }
  16. // 排列杯子
  17. arrangeCups() {
  18. const startX = 40; //水杯的宽度一半
  19. const spacing = 150;
  20. this.cups.forEach((cup, index) => {
  21. cup.setPosition(startX + index * spacing, 0, 0);
  22. console.log('cup position: ', cup.position);
  23. });
  24. }
  25. addCup(cup: Node) {
  26. cup.setParent(this.outNodes);
  27. this.arrangeCups();
  28. }
  29. removeCup(cup: Node) {
  30. cup.removeFromParent();
  31. this.arrangeCups();
  32. }
  33. getCups() {
  34. return this.cups;
  35. }
  36. }