|
@@ -30,8 +30,8 @@ export class LevelAction extends Component {
|
|
|
private originCupPositions = new Map<string, Vec3>(); // 改用唯一ID记录
|
|
|
|
|
|
start() {
|
|
|
- this.registerListener();
|
|
|
this.generateInitialCups();
|
|
|
+ this.registerListener();
|
|
|
}
|
|
|
|
|
|
onDestroy() {
|
|
@@ -41,9 +41,9 @@ 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, (uuid: string) => {
|
|
|
- const cupNode = find(uuid) as Node;
|
|
|
- if (cupNode) {
|
|
|
- this.spawnNewOriginCup(cupNode);
|
|
|
+ const targetPos = this.originCupPositions.get(uuid);
|
|
|
+ if (targetPos) {
|
|
|
+ this.spawnNewOriginCup(targetPos);
|
|
|
}
|
|
|
}, this);
|
|
|
EventDispatcher.instance.on(GameEvent.EVENT_COCKTAIL_CUP_DESTROYED, this.handleCupDestroyed, this);
|
|
@@ -125,7 +125,7 @@ export class LevelAction extends Component {
|
|
|
// 在生成初始原浆杯时记录位置
|
|
|
const id = originCupNode.uuid; // 使用节点唯一ID
|
|
|
this.originCupPositions.set(id, originCupNode.position.clone());
|
|
|
- // console.log('在生成初始原浆杯时记录位置: ', originCupNode.position);
|
|
|
+ console.log('在生成初始原浆杯时记录id : ', id, originCupNode.position);
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -294,11 +294,7 @@ export class LevelAction extends Component {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private async spawnNewOriginCup(destroyedCup: Node) {
|
|
|
- // 获取被销毁杯子的初始位置
|
|
|
- const id = destroyedCup.uuid;
|
|
|
- const targetPos = this.originCupPositions.get(id) || Vec3.ZERO;
|
|
|
-
|
|
|
+ private async spawnNewOriginCup(targetPos: Vec3) {
|
|
|
// 创建新原浆杯
|
|
|
const height = TakeGobletGlobalInstance.instance.generateOriginCupHeight();
|
|
|
const prefab = await TakeGobletGlobalInstance.instance.loadAsyncOriginCup(height);
|
|
@@ -354,28 +350,6 @@ export class LevelAction extends Component {
|
|
|
private handleCupDestroyed(destroyedCup: Node) {
|
|
|
// 从outArea移除被销毁的杯子
|
|
|
this.outArea.removeCup(destroyedCup);
|
|
|
- // 补充新杯子到等待区
|
|
|
- this.generateNewCupToWaitArea();
|
|
|
- }
|
|
|
-
|
|
|
- private async generateNewCupToWaitArea() {
|
|
|
- const configs = TakeGobletGlobalInstance.instance.getInitialCupsConfig();
|
|
|
- const randomConfig = configs[Math.floor(Math.random() * configs.length)];
|
|
|
-
|
|
|
- const prefab = await TakeGobletGlobalInstance.instance.loadAsyncCocktail(randomConfig.height);
|
|
|
- const newCup = instantiate(prefab);
|
|
|
- const cupComp = newCup.getComponent(CocktailCup)!;
|
|
|
-
|
|
|
- cupComp.cupColor = TakeGobletGlobalInstance.instance.getRandomColor();
|
|
|
- cupComp.reset();
|
|
|
-
|
|
|
- this.waitArea.addCup(newCup);
|
|
|
- }
|
|
|
-
|
|
|
- // 新增重置方法
|
|
|
- public resetLevel() {
|
|
|
- this.originCupPositions.clear();
|
|
|
- this.generateInitialCups();
|
|
|
}
|
|
|
}
|
|
|
|