| 1234567891011121314151617181920212223242526272829 |
- import { _decorator, Component, Node, UITransform, Prefab, instantiate, Vec3 } from 'cc';
- import { ResourcesUtils } from '../core/resourceManager/ResourcesUtils';
- const { ccclass, property } = _decorator;
- @ccclass('ColorRibbonBox')
- export class ColorRibbonBox extends Component {
- @property({ tooltip: "彩带(不填写默认为当前node)", type: Node }) public ribbonBox: Node;
- @property({ tooltip: "加载特效间隔时间,单位秒" }) public interval: number = 0.5;
- @property({ tooltip: "加载特效次数" }) public times: number = 20;
- @property({ tooltip: "特效密集度" }) public spacing: number = 40;
- start() {
- if (!this.ribbonBox) {
- this.ribbonBox = this.node;
- }
- this.schedule(this.addRibbon, this.interval, this.times);
- }
- public async addRibbon() {
- let temp = Math.ceil(this.ribbonBox.getComponent(UITransform).width / this.spacing);
- for (let i = 0; i < temp + 1; i++) {
- let _ribbon = await ResourcesUtils.load<Prefab>("Prefabs/SpecialEffects/彩带move", null, this.node);
- let ribbon = instantiate(_ribbon);
- ribbon.parent = this.ribbonBox;
- let _X = this.ribbonBox.getComponent(UITransform).width / 2 - ((i - 1) * this.spacing + (Math.random() * this.spacing));
- ribbon.setPosition(new Vec3(_X));
- }
- }
- }
|