Эх сурвалжийг харах

添加调酒杯 改变父类 平移

woso_javan 3 сар өмнө
parent
commit
2ae55406ce

+ 1 - 1
assets/module_take_goblet/Prefabs/Levels/lvl_1.prefab

@@ -535,7 +535,7 @@
     },
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": -270,
+      "x": -255,
       "y": 0,
       "z": 0
     },

+ 17 - 3
assets/module_take_goblet/Script/Component/OutArea.ts

@@ -1,4 +1,4 @@
-import { _decorator, Component, Node } from 'cc';
+import { _decorator, Component, Node, tween, Vec3 } from 'cc';
 const { ccclass, property, executeInEditMode } = _decorator;
 
 @ccclass('OutArea')
@@ -24,10 +24,9 @@ export class OutArea extends Component {
     // 排列杯子
     arrangeCups() {
         const startX = 40; //水杯的宽度一半
-        const spacing = 150;
+        const spacing = 80;
         this.cups.forEach((cup, index) => {
             cup.setPosition(startX + index * spacing, 0, 0);
-            console.log('cup position: ', cup.position);
         });
     }
 
@@ -44,6 +43,21 @@ export class OutArea extends Component {
     getCups() {
         return this.cups;
     }
+
+    // 添加带动画排列方法
+    arrangeCupsWithAnimation() {
+        const startX = -200; // 从左侧开始
+        const spacing = 120; // 正间距向右排列
+
+        this.cups.forEach((cup, index) => {
+            const targetPos = new Vec3(startX + index * spacing, 0, 0);
+            if (!cup.position.equals(targetPos)) {
+                tween(cup)
+                    .to(0.3, { position: targetPos }, { easing: 'sineOut' })
+                    .start();
+            }
+        });
+    }
 }
 
 

+ 17 - 2
assets/module_take_goblet/Script/Component/WaitArea.ts

@@ -1,4 +1,4 @@
-import { _decorator, Component, Node } from 'cc';
+import { _decorator, Component, Node, tween, Vec3 } from 'cc';
 const { ccclass, property, executeInEditMode } = _decorator;
 
 @ccclass('WaitArea')
@@ -24,7 +24,7 @@ export class WaitArea extends Component {
     // 从右向左排列
     arrangeCups() {
         const startX = -40;
-        const spacing = -150;
+        const spacing = -80;
 
         this.cups.forEach((cup, index) => {
             cup.setPosition(startX + index * spacing, 0, 0);
@@ -50,6 +50,21 @@ export class WaitArea extends Component {
     getCups(): Node[] {
         return this.waitNodes.children;
     }
+
+    // 添加带动画排列方法
+    arrangeCupsWithAnimation() {
+        const startX = 400; // 从右侧开始
+        const spacing = -120; // 负间距向右移动
+
+        this.cups.forEach((cup, index) => {
+            const targetPos = new Vec3(startX + index * spacing, 0, 0);
+            if (!cup.position.equals(targetPos)) {
+                tween(cup)
+                    .to(0.3, { position: targetPos }, { easing: 'sineOut' })
+                    .start();
+            }
+        });
+    }
 }
 
 

+ 30 - 0
assets/module_take_goblet/Script/LevelAction.ts

@@ -211,9 +211,39 @@ export class LevelAction extends Component {
         } else {
             // 所有水层处理完毕,销毁原浆杯
             originCup.destroyOriginCup();
+            this.addWaitCupToOutArea();
         }
     }
 
+    // 添加等待区杯子到调酒区
+    private addWaitCupToOutArea() {
+        // 获取等待区最右侧杯子
+        const waitCups = this.waitArea.getCups();
+        if (waitCups.length === 0) return;
+
+        const lastCup = waitCups[waitCups.length - 1];
+
+        // 改变父节点到调酒区
+        lastCup.setParent(this.outArea.node);
+
+        // 从等待区移除
+        this.waitArea.getCups().pop();
+
+        // 调酒区所有杯子向右平移80
+        this.outArea.getCups().forEach(cup => {
+            tween(cup)
+                .by(0.3, { position: new Vec3(80, 0, 0) }, { easing: 'sineOut' })
+                .start();
+        });
+
+        // 等待区剩余杯子向右平移80
+        this.waitArea.getCups().forEach(cup => {
+            tween(cup)
+                .by(0.3, { position: new Vec3(80, 0, 0) }, { easing: 'sineOut' })
+                .start();
+        });
+    }
+
     private async pourAnimation(
         origin: Node,
         target: Node,