import { _decorator, Component, Node, Sprite, SpriteFrame, Vec3, UITransform, v3 } from 'cc'; import { Sound } from '../core/sound/Sound'; import { Utils } from '../core/utils/Utils'; import { BezierComponent } from '../Turntable/BezierComponent'; const { ccclass, property } = _decorator; @ccclass('UIEffect') export class UIEffect extends Component { @property({ type: [SpriteFrame], tooltip: "粒子合集" }) partics: Array = []; @property({ type: [Node], tooltip: "结束点合集" }) endPoints: Array = []; @property({ tooltip: "播放音效所需的声音组件", type: Sound }) public sound: Sound; public async showBezierRedBagEffect(type: number, effectNode?: Node, particCount: number = 11, startPoint: Vec3 = v3(0, 0, 0)) { this.sound && this.sound.play(particCount == 1 ? 1 : 0); for (let i = 0; i < particCount; i++) { let node = new Node(); //附加图片显示组件 node.addComponent(Sprite); node.getComponent(Sprite)!.spriteFrame = this.partics[type]; node.addComponent(BezierComponent); let bezierComponent = node.getComponent(BezierComponent); bezierComponent.startPoint = startPoint; bezierComponent.ctrl1Point = new Vec3(Utils.random_both(300, -300), Utils.random_both(0, -500)) bezierComponent.ctrl2Point = new Vec3(Utils.random_both(100, -100), Utils.random_both(300, -300)) bezierComponent.endPoint = this.endPoints[type].position; node.setPosition(0, 0); if (effectNode) { effectNode.addChild(node); } else { this.node.addChild(node); } } } }