12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- import { _decorator, Component, Node } from 'cc';
- const { ccclass, property, executeInEditMode } = _decorator;
- @ccclass('OutArea')
- @executeInEditMode
- export class OutArea extends Component {
- @property(Node)
- outNodes: Node = null!;
- // 直接使用outNodes的子节点管理
- get cups() {
- return this.outNodes.children;
- }
- start() {
- }
- update(deltaTime: number) {
- }
- // 排列杯子
- arrangeCups() {
- const startX = 40; //水杯的宽度一半
- const spacing = 150;
- this.cups.forEach((cup, index) => {
- cup.setPosition(startX + index * spacing, 0, 0);
- console.log('cup position: ', cup.position);
- });
- }
- addCup(cup: Node) {
- cup.setParent(this.outNodes);
- this.arrangeCups();
- }
- removeCup(cup: Node) {
- cup.removeFromParent();
- this.arrangeCups();
- }
- getCups() {
- return this.cups;
- }
- }
|