import { _decorator, Component, Node, Prefab, instantiate, EventHandler } from 'cc'; import { ResourcesUtils } from '../core/resourceManager/ResourcesUtils'; import { PkRedPrizeItem } from '../Item/pkRedPrizeItem'; const { ccclass, property } = _decorator; @ccclass('PkRedPrizeWin') export class PkRedPrizeWin extends Component { @property({ tooltip: "奖品展示框", type: Node }) public prizeList: Node; @property({ tooltip: "领取按钮", type: Node }) public getPrizeBtn: Node; @property({ tooltip: "回调", type: EventHandler }) public backFun: EventHandler; start() { // [3] } /** * 初始化 * @param data 0:奖励数据 */ public async setData(data: any[]) { let prizeData = data[0]; prizeData.sort(function (a, b) { if (a.type == b.type) { return a.value - b.value; } else { return b.type - a.type; } }) for (let i = 0; i < prizeData.length; i++) { let prefab = await ResourcesUtils.load("Prefabs/Item/切磋红包奖励Item", null, this.node); let prizeItem = instantiate(prefab); if (i == prizeData.length - 1) { prizeItem.getComponent(PkRedPrizeItem).setData(prizeData[i].type, prizeData[i].value, this.backFun, i); } else { prizeItem.getComponent(PkRedPrizeItem).setData(prizeData[i].type, prizeData[i].value, null, i); } prizeItem.parent = this.prizeList; } } public showCloseBtn() { this.getPrizeBtn.active = true; } }