import { _decorator, Component, Node, Animation, EventHandler, Button, Prefab, instantiate, Vec3 } from 'cc'; import { ResourceLoader } from '../core/resourceManager/ResourceLoader'; import { Sound } from '../core/sound/Sound'; import { Firework } from './Firework'; const { ccclass, property } = _decorator; @ccclass('ShowRedPrizeAnim') export class ShowRedPrizeAnim extends Component { @property({ tooltip: "音效组件", type: Sound }) private sound: Sound; @property({ tooltip: "背景", type: Button }) private bg: Button; @property({ tooltip: "烟花节点", type: Node }) private fireworkNode: Node; start() { } public animEndBack() { this.sound.play(1); this.bg.interactable = true; this.effect(); } //烟花特效 private async effect() { let r = 180; let rRandom = 180; let positionArray = []; for (let i = 1; i < 15; i++) { let rotation = 90 * Math.random(); let y = Math.sin(rotation * ((2 * Math.PI) / 360)) * r; let x = Math.cos(rotation * ((2 * Math.PI) / 360)) * r; positionArray.push({ x: x + (Math.random() * rRandom), y: y + (Math.random() * rRandom) }); positionArray.push({ x: -x - (Math.random() * rRandom), y: y + (Math.random() * rRandom) }); positionArray.push({ x: x + (Math.random() * rRandom), y: -y - (Math.random() * rRandom) }); positionArray.push({ x: -x - (Math.random() * rRandom), y: -y - (Math.random() * rRandom) }); } let load = this.getComponent(ResourceLoader); for (let i = 0; i < positionArray.length; i++) { let prefab = await load.load("prefabs/ui/fireworkEffect", Prefab); let firework = instantiate(prefab); firework.setPosition(new Vec3(0, 0, 0)); firework.parent = this.fireworkNode; firework.getComponent(Firework).playEffect(positionArray[i]); } } }