import { _decorator, Component, Node, Sprite, Animation, Prefab, instantiate, Widget, Vec3, UITransform, tween, Tween, SpriteFrame, EventHandler, Label } from 'cc'; import { ResourcesUtils } from '../core/resourceManager/ResourcesUtils'; import { ConfigData } from '../Data/ConfigData'; import { g } from '../Data/g'; const { ccclass, property } = _decorator; @ccclass('PkRedPrizeItem') export class PkRedPrizeItem extends Component { @property({ tooltip: "开始光圈特效", type: Node }) public turnLightAnim: Node; @property({ tooltip: "出场特效", type: Node }) public comeOutAnim: Node; @property({ tooltip: "奖品", type: Sprite }) public prize: Sprite; @property({ tooltip: "粒子光效box", type: Node }) public particleBox: Node; @property({ tooltip: "神石文本", type: Node }) public dimaondTxt: Node; @property({ tooltip: "金额文本", type: Label }) public moneyTxt: Label; @property({ tooltip: "金额文本框", type: Node }) public moneyTxtBox: Node; public animBackFun: EventHandler; start() { } public comeOut() { this.comeOutAnim.getComponent(Animation).play(); } /** * 设置奖品图片 * @param type 0:神将,1:神石 * @param icon 奖品编号 * @param backFun 窗口关闭回调 */ public async setData(type: number, icon: number, backFun: EventHandler = null, prizeId: number) { if (type == 0) { let imgRoles = await ResourcesUtils.load("Roles/" + icon + "/spriteFrame", SpriteFrame, this.node); this.prize.spriteFrame = imgRoles; g.gameData.addMyLocalGenral(-1, icon); } else { let imgRed = await ResourcesUtils.load("Images/red/redOpening/spriteFrame", SpriteFrame, this.node); this.prize.spriteFrame = imgRed; this.moneyTxtBox.active = true; this.dimaondTxt.active = true; this.dimaondTxt.getComponent(Label).string = "(" + icon + "神石)"; this.moneyTxt.string = (icon / ConfigData.configMap.get("systemConfig").moneyRate) + ""; g.userData.diamond += icon; } if (backFun) { this.animBackFun = backFun; } let _anim = this.turnLightAnim.getComponent(Animation); this.scheduleOnce(function () { _anim.play(); }, prizeId * 1.2); } //添加粒子特效 public async addParticle(num: number, starY: number = 100, endYMix: number = 500) { for (let i = 0; i < num; i++) { let prefab = await ResourcesUtils.load("Prefabs/SpecialEffects/粒子光效", null, this.node); let particle = instantiate(prefab); particle.parent = this.particleBox; let _w = this.particleBox.getComponent(UITransform).width; let tempx = Math.random() * (_w * 0.8); let _x = tempx > ((_w * 0.8) / 2) ? ((_w * 0.8) / 2) - tempx : tempx; particle.setPosition(new Vec3(_x, starY + Math.random() * 200)); let _scale = Math.random() * 0.5 + 0.5; particle.scale = new Vec3(_scale, _scale, 1); let endY = Math.random() * 300 + endYMix; let endX = Math.random() * (_w + 100); endX = endX < ((_w + 100) / 2) ? endX : (_w + 100) / 2 - endX; let t = tween(particle); t.to(1.5, { position: new Vec3(endX, endY, 0) }).start(); } } public animEndFun() { this.animBackFun && this.animBackFun.emit([]); } }