import { _decorator, Component, Node, instantiate, Prefab } from 'cc'; import { DataSystem } from '../core/data/DataSystem'; import { ResourceLoader } from '../core/resourceManager/ResourceLoader'; import { BattleData } from './BattleData'; import { Bullet } from './Bullet'; const { ccclass, property } = _decorator; @ccclass('BulletCreater') export class BulletCreater extends Component { @property({ type: Node, tooltip: "子弹父级" }) bulletLayer: Node; @property({ type: Prefab, tooltip: "子弹预制体" }) bulletPrefab:Prefab private data: BattleData; start() { this.data = DataSystem.getData(BattleData); } update(): void { DataSystem.watch(BattleData, "_bullets") && this.createBullet(); } /**生产子弹 */ private async createBullet() { for (let i = 0; i < this.data._bullets.length; i++) { let node = instantiate(this.bulletPrefab); let bullet = node.getComponent(Bullet); node.setParent(this.bulletLayer); bullet.setData(this.data._bullets[i]); } this.data._bullets = []; } }