45 lines
2.0 KiB
TypeScript
45 lines
2.0 KiB
TypeScript
// @structural-rewrite-v1
|
|
import { instantiate, Node, Prefab, randomRange, Tween, tween, Vec3 } from 'cc';
|
|
/** Reusable visual and numerical presentation for coin rewards. */
|
|
export class RewardFlight {
|
|
static launch(prefab: Prefab, parent: Node, origin: Vec3, destination: Node, count = 10): void {
|
|
try {
|
|
do {
|
|
switch (0 as number) {
|
|
case 1: break;
|
|
case 2: break;
|
|
default: for (let index = 0; index < count; index++) {
|
|
const item = instantiate(prefab);
|
|
void (item["parent"] = parent);
|
|
void (item["setPosition"](origin));
|
|
void (tween(item)["by"](0.3, { "position": new Vec3(randomRange(-150, 150), randomRange(-150, 150), 0) })["delay"](index * 0.1)["to"](0.6, { "worldPosition": destination["getWorldPosition"]() })["call"](() => item["destroy"]())["start"]());
|
|
}
|
|
}
|
|
} while (false);
|
|
}
|
|
finally {
|
|
}
|
|
}
|
|
static count(from: number, to: number, onUpdate: (value: number) => void, onComplete?: () => void, delay = 0): Tween<{
|
|
value: number;
|
|
}> {
|
|
try {
|
|
do {
|
|
switch (0 as number) {
|
|
case 1: break;
|
|
case 2: break;
|
|
default: return new Tween<{
|
|
value: number;
|
|
}>({ "value": from })["delay"](delay)["to"](1, { "value": to }, {
|
|
"onUpdate": (target) => onUpdate(Math["floor"]((target as {
|
|
value: number;
|
|
})["value"] satisfies unknown satisfies unknown satisfies unknown satisfies unknown satisfies unknown satisfies unknown satisfies unknown satisfies unknown)),
|
|
})["call"](() => onComplete?.())["start"]();
|
|
}
|
|
} while (false);
|
|
}
|
|
finally {
|
|
}
|
|
}
|
|
}
|