|
@@ -27,6 +27,8 @@ export class LevelAction extends Component {
|
|
|
@property(Node)
|
|
|
goblets: Node = null!; //原浆区
|
|
|
|
|
|
+ private originCupPositions = new Map<Node, Vec3>(); // 记录原浆杯初始位置
|
|
|
+
|
|
|
start() {
|
|
|
this.registerListener();
|
|
|
this.generateInitialCups(); // 自动初始化
|
|
@@ -38,10 +40,14 @@ export class LevelAction extends Component {
|
|
|
|
|
|
registerListener() {
|
|
|
EventDispatcher.instance.on(GameEvent.EVENT_CLICK_ORIGIN_CUP, this.handlePourOriginCup, this);
|
|
|
+ EventDispatcher.instance.on(GameEvent.EVENT_ORIGIN_CUP_DESTROYED, (cupNode: Node) => {
|
|
|
+ this.spawnNewOriginCup(cupNode); // 传递被销毁的节点
|
|
|
+ }, this);
|
|
|
}
|
|
|
|
|
|
unregisterListener() {
|
|
|
EventDispatcher.instance.off(GameEvent.EVENT_CLICK_ORIGIN_CUP, this.handlePourOriginCup, this);
|
|
|
+ EventDispatcher.instance.off(GameEvent.EVENT_ORIGIN_CUP_DESTROYED, this.spawnNewOriginCup, this);
|
|
|
}
|
|
|
|
|
|
private async generateInitialCups() {
|
|
@@ -91,6 +97,7 @@ export class LevelAction extends Component {
|
|
|
const outCups = this.outArea.getCups() as Node[];
|
|
|
const waitCups = this.waitArea.getCups() as Node[];
|
|
|
|
|
|
+ // DOTO 取前7个杯子颜色后期修改
|
|
|
const allCups = [...outCups, ...waitCups].slice(0, 7);
|
|
|
const colors = allCups.map(cup => {
|
|
|
const comp = cup.getComponent(CocktailCup);
|
|
@@ -109,6 +116,9 @@ export class LevelAction extends Component {
|
|
|
waterNode.active = true;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 在生成初始原浆杯时记录位置
|
|
|
+ this.originCupPositions.set(originCupNode, originCupNode.position.clone());
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -217,8 +227,6 @@ export class LevelAction extends Component {
|
|
|
.call(() => resolve())
|
|
|
.start();
|
|
|
});
|
|
|
-
|
|
|
- // 移除返回原位的逻辑
|
|
|
}
|
|
|
|
|
|
// 新增辅助方法
|
|
@@ -229,5 +237,61 @@ export class LevelAction extends Component {
|
|
|
activeWaters[topIndex].active = false;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private async spawnNewOriginCup(destroyedCup: Node) {
|
|
|
+ // 获取被销毁杯子的初始位置
|
|
|
+ const targetPos = this.originCupPositions.get(destroyedCup) || Vec3.ZERO;
|
|
|
+
|
|
|
+ // 创建新原浆杯
|
|
|
+ const height = TakeGobletGlobalInstance.instance.generateOriginCupHeight();
|
|
|
+ const prefab = await TakeGobletGlobalInstance.instance.loadAsyncOriginCup(height);
|
|
|
+ const newCup = instantiate(prefab);
|
|
|
+
|
|
|
+ // 设置初始位置(屏幕左侧)
|
|
|
+ const uiTransform = this.node.getComponent(UITransform)!;
|
|
|
+ newCup.setPosition(-uiTransform.width / 2, 0, 0);
|
|
|
+ this.goblets.addChild(newCup);
|
|
|
+
|
|
|
+ // 记录新杯子的初始位置
|
|
|
+ this.originCupPositions.set(newCup, targetPos);
|
|
|
+
|
|
|
+ // 移动动画到原位置
|
|
|
+ tween(newCup)
|
|
|
+ .to(0.5, { position: targetPos })
|
|
|
+ .start();
|
|
|
+
|
|
|
+ // DOTO 获取颜色配置
|
|
|
+ const colors = this.getAvailableColors(5); // 获取前5个颜色
|
|
|
+ this.setupOriginCupColors(newCup, colors);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取可用颜色
|
|
|
+ private getAvailableColors(count: number): WaterColors[] {
|
|
|
+ const outCups = this.outArea.getCups();
|
|
|
+ const waitCups = this.waitArea.getCups();
|
|
|
+ const allCups = [...outCups, ...waitCups].slice(0, count);
|
|
|
+
|
|
|
+ return allCups.map(cup => {
|
|
|
+ const comp = cup.getComponent(CocktailCup);
|
|
|
+ return comp ? comp.cupColor : WaterColors.Blue;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置原浆杯颜色
|
|
|
+ private setupOriginCupColors(cupNode: Node, colors: WaterColors[]) {
|
|
|
+ const originCup = cupNode.getComponent(OriginCup)!;
|
|
|
+ const waters = originCup.waters.children;
|
|
|
+
|
|
|
+ // 暂时写死5层水
|
|
|
+ const waterCount = 5;
|
|
|
+ for (let i = 0; i < waterCount; i++) {
|
|
|
+ const waterNode = waters[i];
|
|
|
+ if (!waterNode) continue;
|
|
|
+
|
|
|
+ const water = waterNode.getComponent(Water)!;
|
|
|
+ water.color = colors[Math.floor(Math.random() * colors.length)];
|
|
|
+ waterNode.active = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|