/** * @file RewardItemComp.ts * @description 结算奖励条目组件(UI 视图层) * * 挂载在 reward_item.prefab 上,用于展示单个非英雄碎片类奖励(金币 / 天赋经验等)。 * 图标在编辑器内直接配置好(Sprite 静态图),组件只负责: * 1. 设置数量文本("+N")。 * 2. 播放入场弹跳动画(scale 0 → 1,backOut)。 * * 英雄碎片奖励不使用本组件,而是复用 clips.prefab + ChipComp(见 VictoryComp.renderRewards)。 */ import { _decorator, Label, tween, v3, Tween } from "cc"; import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp"; const { ccclass, property } = _decorator; /** 奖励条目入场动画时长(秒) */ const ENTER_DURATION = 0.35; /** * RewardItemComp —— 单个结算奖励条目视图组件 */ @ccclass('RewardItemComp') @ecs.register('RewardItemComp', false) export class RewardItemComp extends CCComp { @property({ type: Label, tooltip: "数量文本(count_label)" }) count_label: Label = null!; /** * 设置奖励数量并播放入场动画。 * @param count 奖励数量(展示为 "+N") */ setReward(count: number) { if (this.count_label) { this.count_label.string = `+${count}`; } this.playEnter(); } /** 入场动画:从 0 缩放弹至 1 */ private playEnter() { Tween.stopAllByTarget(this.node); this.node.setScale(0, 0, 1); tween(this.node) .to(ENTER_DURATION, { scale: v3(1, 1, 1) }, { easing: 'backOut' }) .start(); } protected onDestroy(): void { Tween.stopAllByTarget(this.node); super.onDestroy(); } /** ECS 组件移除时销毁节点 */ reset() { this.node.destroy(); } }