Przeglądaj źródła

暂存杯修改

woso_javan 3 miesięcy temu
rodzic
commit
0038c96f66

+ 2 - 1
assets/module_take_goblet/Script/Component/OriginCup.ts

@@ -131,7 +131,8 @@ export class OriginCup extends Component {
         }
     }
 
-    fillWater() {
+    /** 倒水动画*/
+    pourWater() {
         const activeWaters = this.waters.children.filter(n => n.active);
         const topIndex = this.waters.children.length - activeWaters.length;
         if (activeWaters.length >= 0) {

+ 25 - 7
assets/module_take_goblet/Script/Component/TempCup.ts

@@ -6,6 +6,13 @@ import { GameEvent } from '../Enum/GameEvent';
 import { GameUtil } from '../GameUtil';
 const { ccclass, property } = _decorator;
 
+//暂存杯状态 默认 接水 倒水
+export enum TempCupState {
+    Default,
+    Pick,
+    PourWater
+}
+
 @ccclass('TempCup')
 export class TempCup extends Component {
 
@@ -62,25 +69,36 @@ export class TempCup extends Component {
             this._currentColor = color;
             let cupColor = new Color(WaterColorHex[color]);
             let waterSpine = waterNode.getComponent(sp.Skeleton)!;
-            console.log(`暂存水的颜色:${WaterColorHex[color]}`)
+            // console.log(`暂存水的颜色:${WaterColorHex[color]}`)
             this.colorB.color = cupColor;
             waterSpine.color = cupColor;
-            waterSpine.setAnimation(0, 'pick_01', false);
-            this.colorB.setAnimation(0, 'pick_01', false);
-            this.cupSkeleton.setAnimation(0, 'pick_01', false);
+            this.playAnimation(TempCupState.Pick);
             this._isFull = true;
             await GameUtil.delay(0.5);
         }
     }
 
-    pour() {
+    playAnimation(state: TempCupState) {
+        let animaStr = state === TempCupState.Pick ? 'pick_01' :
+            state === TempCupState.PourWater ? 'pour_01' : 'idle';
+
+        const waterNode = this.waters.children[0];
+        if (waterNode && waterNode.getComponent(sp.Skeleton)) {
+            let waterSpine = waterNode.getComponent(sp.Skeleton)!;
+            waterSpine.setAnimation(0, animaStr, false);
+            this.colorB.setAnimation(0, animaStr, false);
+            this.cupSkeleton.setAnimation(0, animaStr, false);
+        }
+    }
 
+    /**暂存杯 倒水动画*/
+    pour() {
+        this.playAnimation(TempCupState.PourWater);
     }
 
     reset() {
-        this.waters.children[0].active = false;
         this._isFull = false;
-        console.log('暂存杯已重置');
+        this.playAnimation(TempCupState.Default);
     }
 
     public getColors(): WaterColors[] {

+ 23 - 35
assets/module_take_goblet/Script/LevelAction.ts

@@ -247,12 +247,11 @@ export class LevelAction extends Component {
                 await this.pourAnimation(
                     originCup.node,
                     targetNode,
-                    color,
                     undefined,
                     targetIsTemp
                 );
 
-                originCup.fillWater();
+                originCup.pourWater();
                 // 更新目标杯
                 if (targetIsTemp) {
                     const tempCupComp = targetNode.getComponent(TempCup)!;
@@ -294,30 +293,38 @@ export class LevelAction extends Component {
             for (const tempCup of filledCups) {
                 const originalPos = tempCup.node.position.clone();
                 const colors = tempCup.getColors();
-                let hasProcessed = false; // 标记是否有处理过颜色
 
                 for (const color of colors) {
                     const targetCup = this.findTargetCupInOutArea(color);
                     if (!targetCup) {
-                        console.log(`颜色${WaterColors[color]}未找到可用调酒杯`);
+                        // console.log(`颜色${WaterColors[color]}未找到可用调酒杯`);
                         continue;
                     }
 
                     await this.pourAnimation(
                         tempCup.node,
                         targetCup.node,
-                        color,
                         originalPos,
                         true
                     );
 
+                    tempCup.pour();
                     const cocktailCup = targetCup.comp;
                     await cocktailCup.addLayer();
-                    hasProcessed = true; // 标记已处理
-                }
-                // 仅当有处理过颜色时才重置暂存杯
-                if (hasProcessed) {
-                    tempCup.reset();
+
+                    await GameUtil.delay(0.2);
+                    // 返回到暂存区初始位置
+                    if (originalPos) {
+                        await new Promise(resolve => {
+                            tween(tempCup.node)
+                                .to(0.3, { position: originalPos })
+                                .call(() => {
+                                    tempCup.reset();
+                                    resolve(true);
+                                })
+                                .start();
+                        });
+                    }
                 }
             }
         } finally {
@@ -381,11 +388,15 @@ export class LevelAction extends Component {
         }
     }
 
-    //倒水移动动画
+    /** 倒水移动动画
+     * @param origin 原杯子
+     * @param target 目标杯子
+     * @param originalPos 原始位置
+     * @param isTempCup 是否是暂存区杯子
+    */
     private async pourAnimation(
         origin: Node,
         target: Node,
-        color: WaterColors,
         originalPos?: Vec3,
         isTempCup: boolean = false
     ) {
@@ -403,9 +414,6 @@ export class LevelAction extends Component {
             localPos.y += 100;
         }
 
-        //播放动画
-        origin.getComponent(OriginCup)?.playAnimation(OriginCupState.Up);
-
         // 移动动画到目标位置
         await new Promise<void>(resolve => {
             tween(origin)
@@ -413,26 +421,6 @@ export class LevelAction extends Component {
                 .call(resolve)
                 .start();
         });
-
-        // 返回到暂存区初始位置
-        if (isTempCup && originalPos) {
-            await new Promise(resolve => {
-                tween(origin)
-                    .to(0.3, { position: originalPos })
-                    .call(resolve)
-                    .start();
-            });
-        }
-    }
-
-    //隐藏原浆杯当前水层 等待倒水动画
-    private async hideCurrentWaterLayer(originCup: OriginCup) {
-        const activeWaters = originCup.waters.children.filter(n => n.active);
-        const topIndex = originCup.waters.children.length - activeWaters.length;
-        if (activeWaters.length >= 0) {
-            originCup.getComponent(OriginCup)?.playAnimation(OriginCupState.PourWater, topIndex + 1);
-            activeWaters[activeWaters.length - 1].active = false;
-        }
     }
 
     private async spawnNewOriginCup(targetPos: Vec3) {