Browse Source

倒水流程 调酒区测试

woso_javan 3 tháng trước cách đây
mục cha
commit
d83a0da9c8

+ 1 - 1
assets/module_take_goblet/Prefabs/Cup/Cocktail/CocktailFour.prefab

@@ -204,7 +204,7 @@
     "__prefab": {
       "__id__": 8
     },
-    "_opacity": 100,
+    "_opacity": 200,
     "_id": ""
   },
   {

+ 1 - 1
assets/module_take_goblet/Prefabs/Cup/Cocktail/CocktailThree.prefab

@@ -204,7 +204,7 @@
     "__prefab": {
       "__id__": 8
     },
-    "_opacity": 100,
+    "_opacity": 200,
     "_id": ""
   },
   {

+ 1 - 1
assets/module_take_goblet/Prefabs/Cup/Cocktail/CocktailTwo.prefab

@@ -204,7 +204,7 @@
     "__prefab": {
       "__id__": 8
     },
-    "_opacity": 100,
+    "_opacity": 200,
     "_id": ""
   },
   {

+ 159 - 21
assets/module_take_goblet/Prefabs/Cup/TempCup.prefab

@@ -25,20 +25,20 @@
         "__id__": 8
       },
       {
-        "__id__": 14
+        "__id__": 23
       }
     ],
     "_active": true,
     "_components": [
       {
-        "__id__": 20
+        "__id__": 29
       },
       {
-        "__id__": 22
+        "__id__": 31
       }
     ],
     "_prefab": {
-      "__id__": 24
+      "__id__": 33
     },
     "_lpos": {
       "__type__": "cc.Vec3",
@@ -213,18 +213,22 @@
     "_parent": {
       "__id__": 1
     },
-    "_children": [],
+    "_children": [
+      {
+        "__id__": 9
+      }
+    ],
     "_active": true,
     "_components": [
       {
-        "__id__": 9
+        "__id__": 18
       },
       {
-        "__id__": 11
+        "__id__": 20
       }
     ],
     "_prefab": {
-      "__id__": 13
+      "__id__": 22
     },
     "_lpos": {
       "__type__": "cc.Vec3",
@@ -255,6 +259,131 @@
     },
     "_id": ""
   },
+  {
+    "__type__": "cc.Node",
+    "_objFlags": 0,
+    "_parent": {
+      "__id__": 8
+    },
+    "_prefab": {
+      "__id__": 10
+    },
+    "__editorExtras__": {}
+  },
+  {
+    "__type__": "cc.PrefabInfo",
+    "root": {
+      "__id__": 9
+    },
+    "asset": {
+      "__uuid__": "b4eb1c00-0285-4fb4-bfb0-c67ff721134e",
+      "__expectedType__": "cc.Prefab"
+    },
+    "fileId": "c46/YsCPVOJYA4mWEpNYRx",
+    "instance": {
+      "__id__": 11
+    },
+    "targetOverrides": null
+  },
+  {
+    "__type__": "cc.PrefabInstance",
+    "fileId": "42D2Q94HxJVpk5doKfIShf",
+    "prefabRootNode": {
+      "__id__": 1
+    },
+    "mountedChildren": [],
+    "mountedComponents": [],
+    "propertyOverrides": [
+      {
+        "__id__": 12
+      },
+      {
+        "__id__": 14
+      },
+      {
+        "__id__": 15
+      },
+      {
+        "__id__": 16
+      },
+      {
+        "__id__": 17
+      }
+    ],
+    "removedComponents": []
+  },
+  {
+    "__type__": "CCPropertyOverrideInfo",
+    "targetInfo": {
+      "__id__": 13
+    },
+    "propertyPath": [
+      "_name"
+    ],
+    "value": "Water"
+  },
+  {
+    "__type__": "cc.TargetInfo",
+    "localID": [
+      "c46/YsCPVOJYA4mWEpNYRx"
+    ]
+  },
+  {
+    "__type__": "CCPropertyOverrideInfo",
+    "targetInfo": {
+      "__id__": 13
+    },
+    "propertyPath": [
+      "_lpos"
+    ],
+    "value": {
+      "__type__": "cc.Vec3",
+      "x": 0,
+      "y": 0,
+      "z": 0
+    }
+  },
+  {
+    "__type__": "CCPropertyOverrideInfo",
+    "targetInfo": {
+      "__id__": 13
+    },
+    "propertyPath": [
+      "_lrot"
+    ],
+    "value": {
+      "__type__": "cc.Quat",
+      "x": 0,
+      "y": 0,
+      "z": 0,
+      "w": 1
+    }
+  },
+  {
+    "__type__": "CCPropertyOverrideInfo",
+    "targetInfo": {
+      "__id__": 13
+    },
+    "propertyPath": [
+      "_euler"
+    ],
+    "value": {
+      "__type__": "cc.Vec3",
+      "x": 0,
+      "y": 0,
+      "z": 0
+    }
+  },
+  {
+    "__type__": "CCPropertyOverrideInfo",
+    "targetInfo": {
+      "__id__": 13
+    },
+    "propertyPath": [
+      "_active"
+    ],
+    "value": false
+  },
   {
     "__type__": "cc.UITransform",
     "_name": "",
@@ -265,7 +394,7 @@
     },
     "_enabled": true,
     "__prefab": {
-      "__id__": 10
+      "__id__": 19
     },
     "_contentSize": {
       "__type__": "cc.Size",
@@ -291,9 +420,9 @@
     "node": {
       "__id__": 8
     },
-    "_enabled": true,
+    "_enabled": false,
     "__prefab": {
-      "__id__": 12
+      "__id__": 21
     },
     "_resizeMode": 0,
     "_layoutType": 2,
@@ -346,14 +475,14 @@
     "_active": true,
     "_components": [
       {
-        "__id__": 15
+        "__id__": 24
       },
       {
-        "__id__": 17
+        "__id__": 26
       }
     ],
     "_prefab": {
-      "__id__": 19
+      "__id__": 28
     },
     "_lpos": {
       "__type__": "cc.Vec3",
@@ -390,11 +519,11 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 14
+      "__id__": 23
     },
     "_enabled": true,
     "__prefab": {
-      "__id__": 16
+      "__id__": 25
     },
     "_contentSize": {
       "__type__": "cc.Size",
@@ -418,11 +547,11 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 14
+      "__id__": 23
     },
     "_enabled": true,
     "__prefab": {
-      "__id__": 18
+      "__id__": 27
     },
     "_customMaterial": null,
     "_srcBlendFactor": 2,
@@ -480,7 +609,7 @@
     },
     "_enabled": true,
     "__prefab": {
-      "__id__": 21
+      "__id__": 30
     },
     "_contentSize": {
       "__type__": "cc.Size",
@@ -508,7 +637,11 @@
     },
     "_enabled": true,
     "__prefab": {
-      "__id__": 23
+      "__id__": 32
+    },
+    "cupHeight": 1,
+    "waters": {
+      "__id__": 8
     },
     "_id": ""
   },
@@ -526,6 +659,11 @@
     },
     "fileId": "c46/YsCPVOJYA4mWEpNYRx",
     "instance": null,
-    "targetOverrides": null
+    "targetOverrides": null,
+    "nestedPrefabInstanceRoots": [
+      {
+        "__id__": 9
+      }
+    ]
   }
 ]

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

@@ -278,9 +278,9 @@
     "_dstBlendFactor": 4,
     "_color": {
       "__type__": "cc.Color",
-      "r": 248,
-      "g": 119,
-      "b": 119,
+      "r": 255,
+      "g": 255,
+      "b": 255,
       "a": 255
     },
     "_spriteFrame": {
@@ -660,9 +660,9 @@
     "_dstBlendFactor": 4,
     "_color": {
       "__type__": "cc.Color",
-      "r": 248,
-      "g": 119,
-      "b": 119,
+      "r": 255,
+      "g": 255,
+      "b": 255,
       "a": 255
     },
     "_spriteFrame": {

+ 18 - 2
assets/module_take_goblet/Script/Component/CocktailCup.ts

@@ -1,5 +1,6 @@
 import { _decorator, Color, Component, Enum, Node, Sprite } from 'cc';
 import { CupHeight, WaterColorHex, WaterColors } from '../TakeGobletGlobalInstance';
+import { Water } from './Water';
 const { ccclass, property, executeInEditMode } = _decorator;
 
 /** 调酒杯组件脚本*/
@@ -28,7 +29,7 @@ export class CocktailCup extends Component {
     @property(Node)
     waters: Node = null!;  //水节点
 
-    private currentLayers: number = 0;
+    currentLayers: number = 0;
 
     onLoad() {
         // 初始化时隐藏所有水层
@@ -41,11 +42,18 @@ export class CocktailCup extends Component {
     }
 
     // 添加水层
-    addLayer() {
+    addLayer(color?: WaterColors) {
         if (this.currentLayers >= this.cupHeight) return;
 
+        // 从下往上激活水层(假设waters子节点0是最底层)
         const waterNode = this.waters.children[this.currentLayers];
+
         if (waterNode) {
+            if (color) {
+                const water = waterNode.getComponent(Water);
+                if (water) water.color = color;
+            }
+
             waterNode.active = true;
             this.currentLayers++;
         }
@@ -60,6 +68,14 @@ export class CocktailCup extends Component {
     isFull(): boolean {
         return this.currentLayers >= this.cupHeight;
     }
+
+    public get currentColor(): WaterColors {
+        return this.cupColor;
+    }
+
+    public get remainingCapacity(): number {
+        return this.cupHeight - this.currentLayers;
+    }
 }
 
 

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

@@ -1,5 +1,8 @@
 import { _decorator, Component, Enum, Node } from 'cc';
 import { CupHeight } from '../TakeGobletGlobalInstance';
+import { LevelAction } from '../LevelAction';
+import { EventDispatcher } from 'db://assets/core_tgx/easy_ui_framework/EventDispatcher';
+import { GameEvent } from '../Enum/GameEvent';
 const { ccclass, property, executeInEditMode } = _decorator;
 
 /** 原浆酒杯组件脚本*/
@@ -13,7 +16,9 @@ export class OriginCup extends Component {
     waters: Node = null!;  //水节点
 
     start() {
-
+        this.node.on(Node.EventType.TOUCH_END, () => {
+            EventDispatcher.instance.emit(GameEvent.EVENT_CLICK_ORIGIN_CUP, this);
+        });
     }
 
     update(deltaTime: number) {

+ 6 - 0
assets/module_take_goblet/Script/Component/Water.ts

@@ -11,6 +11,7 @@ export class Water extends Component {
     get color() {
         return this._color;
     }
+
     set color(value: WaterColors) {
         this._color = value;
         this.updateColor();
@@ -28,5 +29,10 @@ export class Water extends Component {
     start() {
         this.updateColor();
     }
+
+    initColor(color: WaterColors) {
+        this._color = color;
+        this.updateColor();
+    }
 }
 

+ 2 - 20
assets/module_take_goblet/Script/Enum/GameEvent.ts

@@ -4,26 +4,8 @@ export class GameEvent {
     /** 游戏开始*/
     static readonly EVENT_GAME_START = 'EVENT_GAME_START';
 
-    /** 点击汽车*/
-    static readonly EVENT_CLICK_CAR = 'EVENT_CLICK_CAR';
-
-    /** 更新Layer*/
-    static readonly EVENT_UPDATE_LAYER = 'EVENT_UPDATE_LAYER';
-
-    /** 检查Layer子节点*/
-    static readonly EVENT_CHECK_LAYER_CHILD = 'EVENT_CHECK_LAYER_CHILD';
-
-    /** 刷新剩余钉子数量*/
-    static readonly EVENT_UPDATE_LEFT_NAIL = 'EVENT_UPDATE_LEFT_NAIL';
-
-    /** 检测是否有钉子可上车*/
-    static readonly EVENT_CHECK_MOVE_TO_CAR = 'EVENT_CHECK_MOVE_TO_CAR';
-
-    /** 检测element子节点长度*/
-    static readonly EVENT_CHECK_ELEMENT_CHILDREN = 'EVENT_CHECK_ELEMENT_CHILDREN';
-
-    /** 磁力事件*/
-    static readonly EVENT_MAGNET = 'EVENT_MAGNET';
+    /** 点击原浆酒杯*/
+    static readonly EVENT_CLICK_ORIGIN_CUP = 'EVENT_CLICK_ORIGIN_CUP';
 
     /** 刷新钉子颜色事件*/
     static readonly EVENT_REFRESH_PIN_COLORS = 'EVENT_REFRESH_PIN_COLORS';

+ 78 - 2
assets/module_take_goblet/Script/LevelAction.ts

@@ -1,4 +1,4 @@
-import { _decorator, BoxCollider2D, Button, CircleCollider2D, Collider2D, Component, find, instantiate, Node, NodeEventType, view } from 'cc';
+import { _decorator, BoxCollider2D, Button, CircleCollider2D, Collider2D, Component, find, instantiate, Node, NodeEventType, tween, view, Vec3, mat4, UITransform } from 'cc';
 import { resLoader, ResLoader } from '../../core_tgx/base/ResLoader';
 import { CupHeight, TakeGobletGlobalInstance, WaterColors } from './TakeGobletGlobalInstance';
 import { OutArea } from './Component/OutArea';
@@ -6,6 +6,8 @@ import { WaitArea } from './Component/WaitArea';
 import { CocktailCup } from './Component/CocktailCup';
 import { OriginCup } from './Component/OriginCup';
 import { Water } from './Component/Water';
+import { EventDispatcher } from '../../core_tgx/easy_ui_framework/EventDispatcher';
+import { GameEvent } from './Enum/GameEvent';
 const { ccclass, property } = _decorator;
 
 @ccclass('LevelAction')
@@ -28,7 +30,16 @@ export class LevelAction extends Component {
         this.generateInitialCups(); // 自动初始化
     }
 
+    onDestroy() {
+        this.unregisterListener();
+    }
+
     registerListener() {
+        EventDispatcher.instance.on(GameEvent.EVENT_CLICK_ORIGIN_CUP, this.handlePourOriginCup, this);
+    }
+
+    unregisterListener() {
+        EventDispatcher.instance.off(GameEvent.EVENT_CLICK_ORIGIN_CUP, this.handlePourOriginCup, this);
     }
 
     private async generateInitialCups() {
@@ -86,11 +97,76 @@ export class LevelAction extends Component {
                 const waterNode = waters[i];
                 const water = waterNode.getComponent(Water);
                 if (water) {
-                    water.color = colors[Math.floor(Math.random() * colors.length)];
+                    water.initColor(colors[Math.floor(Math.random() * colors.length)]);
                     waterNode.active = true;
                 }
             }
         });
     }
+
+    public async handlePourOriginCup(originCup: OriginCup) {
+        // 如果子节点0是底层,需要反转顺序
+        const colors: WaterColors[] = [];
+        for (let i = originCup.waters.children.length - 1; i >= 0; i--) {
+            const waterNode = originCup.waters.children[i];
+            if (waterNode.active) {
+                const water = waterNode.getComponent(Water)!;
+                colors.push(water.color);
+            }
+        }
+
+        // 处理每个颜色层(从顶层开始)
+        for (const color of colors) {
+            const targetCup = this.findTargetCupInOutArea(color);
+            if (!targetCup) {
+                console.log(`未找到颜色为${WaterColors[color]}的调酒杯,停止倒水`);
+                return;
+            }
+
+            await this.pourAnimation(originCup.node, targetCup.node, color);
+
+            // 隐藏当前处理的水层(顶层)
+            const activeWaters = originCup.waters.children.filter(n => n.active);
+            if (activeWaters.length > 0) {
+                const topIndex = activeWaters.length - 1;
+                activeWaters[topIndex].active = false;
+            }
+        }
+    }
+
+    private findTargetCupInOutArea(color: WaterColors): CocktailCup | null {
+        // 严格过滤调酒区杯子
+        const validCups = this.outArea.getCups()
+            .map(node => node.getComponent(CocktailCup))
+            .filter(cup =>
+                cup !== null &&
+                cup.cupColor === color &&
+                !cup.isFull()
+            ) as CocktailCup[];
+
+        // 优先选择剩余容量最小的杯子(后进先满)
+        return validCups.sort((a, b) => a.remainingCapacity - b.remainingCapacity)[0] || null;
+    }
+
+    private async pourAnimation(origin: Node, target: Node, color: WaterColors) {
+        // 使用UITransform转换坐标
+        const targetWorldPos = target.worldPosition;
+        const originParent = origin.parent!;
+        const localPos = originParent.getComponent(UITransform)!.convertToNodeSpaceAR(targetWorldPos);
+        localPos.y += 150; // Y轴偏移
+
+        await new Promise<void>(resolve => {
+            tween(origin)
+                .to(0.3, { position: localPos })
+                .call(() => resolve())
+                .start();
+        });
+
+        // 添加水层并设置颜色
+        const cocktailCup = target.getComponent(CocktailCup);
+        if (cocktailCup && !cocktailCup.isFull()) {
+            cocktailCup.addLayer(color);
+        }
+    }
 }