|
@@ -1,11 +1,58 @@
|
|
-import { _decorator, Component, Node } from 'cc';
|
|
|
|
|
|
+import { _decorator, Component, Node, tween, UITransform, Vec3, view } from 'cc';
|
|
import { TempCup } from './TempCup';
|
|
import { TempCup } from './TempCup';
|
|
|
|
+import { GameEvent } from '../Enum/GameEvent';
|
|
|
|
+import { EventDispatcher } from 'db://assets/core_tgx/easy_ui_framework/EventDispatcher';
|
|
const { ccclass, property } = _decorator;
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
@ccclass('TempCups')
|
|
@ccclass('TempCups')
|
|
export class TempCups extends Component {
|
|
export class TempCups extends Component {
|
|
start() {
|
|
start() {
|
|
|
|
+ this.registerEvent();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected onDestroy(): void {
|
|
|
|
+ EventDispatcher.instance.off(GameEvent.EVENT_MOVE_OUT, this.onMoveOut, this);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ private registerEvent(): void {
|
|
|
|
+ EventDispatcher.instance.on(GameEvent.EVENT_MOVE_OUT, this.onMoveOut, this);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private async onMoveOut(): Promise<void> {
|
|
|
|
+ console.log('执行移出操作');
|
|
|
|
+
|
|
|
|
+ // 获取前三个子节点(最左侧的三个杯子)
|
|
|
|
+ const cupsToProcess = this.node.children.slice(0, 3)
|
|
|
|
+ .map(node => node.getComponent(TempCup))
|
|
|
|
+ .filter(cup => cup && cup.isFull);
|
|
|
|
+
|
|
|
|
+ if (cupsToProcess.length === 0) {
|
|
|
|
+ console.log('没有可处理的暂存杯');
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 并行执行所有动画
|
|
|
|
+ const tasks = cupsToProcess.map(cup => {
|
|
|
|
+ return new Promise<void>((resolve) => {
|
|
|
|
+ // 保存原始位置
|
|
|
|
+ const originalPos = cup.node.position.clone();
|
|
|
|
+ const screenWidth = view.getVisibleSize().width;
|
|
|
|
+ const targetX = -screenWidth / 2 - cup.node.getComponent(UITransform)!.width * 1.5;
|
|
|
|
+ const targetY = cup.node.position.y + Math.random() * 100;
|
|
|
|
+ // 创建移动动画
|
|
|
|
+ tween(cup.node)
|
|
|
|
+ .to(0.5, { position: new Vec3(targetX, targetY, 0) }, { easing: 'sineOut' })
|
|
|
|
+ .call(() => {
|
|
|
|
+ cup.node.position = originalPos; // 将位置重置到动画前保存的原始位置
|
|
|
|
+ cup.reset(); // 重置水杯状态
|
|
|
|
+ resolve();
|
|
|
|
+ })
|
|
|
|
+ .start();
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ await Promise.all(tasks);
|
|
|
|
+ console.log('所有暂存杯处理完成');
|
|
}
|
|
}
|
|
|
|
|
|
/** 查找暂存区空杯*/
|
|
/** 查找暂存区空杯*/
|
|
@@ -16,10 +63,6 @@ export class TempCups extends Component {
|
|
.find(cup => cup && !cup.isFull && !cup.iconAd) || null;
|
|
.find(cup => cup && !cup.isFull && !cup.iconAd) || null;
|
|
}
|
|
}
|
|
|
|
|
|
- update(deltaTime: number) {
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
// 新增获取已填充的暂存杯
|
|
// 新增获取已填充的暂存杯
|
|
public getFilledCups(): TempCup[] {
|
|
public getFilledCups(): TempCup[] {
|
|
return this.node.children
|
|
return this.node.children
|