|
|
|
|
|
|
|
|
|
import { _decorator, Component, Node, tween, Tween, Vec3 } from 'cc';
|
|
|
|
|
const { ccclass } = _decorator;
|
|
|
|
|
|
|
|
|
|
/** 蹦跳峰值相对起点世界 Y 偏移(与乾坤袋回收飘桃一致) */
|
|
|
|
|
const BOUNCE_WORLD_OFFSET_Y = 50;
|
|
|
|
|
/** 直飞基础时长(秒) */
|
|
|
|
|
const FLY_DIRECT_BASE_SEC = 0.65;
|
|
|
|
|
/** 直飞随机附加时长(秒) */
|
|
|
|
|
const FLY_DIRECT_RANDOM_SEC = 0.15;
|
|
|
|
|
|
|
|
|
|
@ccclass('CoinFly')
|
|
|
|
|
export class CoinFly extends Component {
|
|
|
|
|
|
|
|
|
|
protected onLoad(): void {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 蹦一下再飘向目标(全程世界坐标,避免挂 ui_fly 后本地 y 偏移变成「往上冒」)。
|
|
|
|
|
* @param endPos 终点世界坐标;null 则只原地弹跳后回池(AI 击杀掉落)
|
|
|
|
|
* @param callfunc 到达回调(传入本节点,便于拆掉临时子节点)
|
|
|
|
|
* @param startDelay 起飞前延迟(秒)
|
|
|
|
|
* @param flySec 飞向终点的时长(秒);≤0 用默认短飞行
|
|
|
|
|
*/
|
|
|
|
|
flyAni(endPos: Vec3 | null, callfunc: ((host?: Node) => void) | null = null, startDelay = 0, flySec = 0): void {
|
|
|
|
|
const node = this.node;
|
|
|
|
|
if (!node?.isValid) return;
|
|
|
|
|
|
|
|
|
|
Tween.stopAllByTarget(node);
|
|
|
|
|
|
|
|
|
|
const start = node.worldPosition.clone();
|
|
|
|
|
const peak = new Vec3(start.x, start.y + BOUNCE_WORLD_OFFSET_Y, start.z);
|
|
|
|
|
|
|
|
|
|
const chain = tween(node)
|
|
|
|
|
.delay(Math.max(0, startDelay))
|
|
|
|
|
.to(0.2, { worldPosition: peak }, { easing: 'backOut' })
|
|
|
|
|
.to(0.2, { worldPosition: start }, { easing: 'backOut' })
|
|
|
|
|
.delay(0.3);
|
|
|
|
|
if (endPos) {
|
|
|
|
|
const sec = flySec > 0 ? flySec : 0.1 + Math.random() * 0.1;
|
|
|
|
|
chain.to(sec, { worldPosition: endPos.clone() });
|
|
|
|
|
}
|
|
|
|
|
chain
|
|
|
|
|
.call(() => {
|
|
|
|
|
callfunc?.(node);
|
|
|
|
|
gg.res.putNode(node);
|
|
|
|
|
})
|
|
|
|
|
.start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 从当前位置直接飘向目标(无蹦跳、无额外等待)。
|
|
|
|
|
* @param endPos 终点世界坐标
|
|
|
|
|
* @param callfunc 到达回调(传入本节点)
|
|
|
|
|
* @param startDelay 起飞前延迟(秒)
|
|
|
|
|
*/
|
|
|
|
|
flyDirectAni(endPos: Vec3, callfunc: ((host?: Node) => void) | null = null, startDelay = 0): void {
|
|
|
|
|
const node = this.node;
|
|
|
|
|
if (!node?.isValid) return;
|
|
|
|
|
|
|
|
|
|
Tween.stopAllByTarget(node);
|
|
|
|
|
const end = endPos.clone();
|
|
|
|
|
|
|
|
|
|
tween(node)
|
|
|
|
|
.delay(Math.max(0, startDelay))
|
|
|
|
|
.to(FLY_DIRECT_BASE_SEC + Math.random() * FLY_DIRECT_RANDOM_SEC, { worldPosition: end }, { easing: 'sineOut' })
|
|
|
|
|
.call(() => {
|
|
|
|
|
callfunc?.(node);
|
|
|
|
|
gg.res.putNode(node);
|
|
|
|
|
})
|
|
|
|
|
.start();
|
|
|
|
|
}
|
|
|
|
|
}
|