import { _decorator, Component, Node, Prefab, instantiate, Vec3, v3, CCInteger } from 'cc'; import { Drone } from './Drone'; const { ccclass, property } = _decorator; @ccclass('DroneManager') export class DroneManager extends Component { @property(Prefab) public dronePrefab: Prefab = null!; // 无人机预制体 // @property(Prefab) // public monsterPrefab: Prefab = null!; // 怪物预制体 @property public spawnPoint: Vec3 = new Vec3(-300, 0, 0); // 无人机发射点 @property public orbitCenter: Vec3 = new Vec3(200, 360, 0); // 轨道中心 @property public orbitA: number = 150; // 椭圆长轴 @property public orbitB: number = 100; // 椭圆短轴 public static Instance: DroneManager = null; public droneCount: number = 0; // 无人机数量 public spawnInterval: number = 1.5; // 发射间隔(秒) private spawnTimer: number = 0; private spawnedCount: number = 0; /**音频时间戳 */ audio_timeStamp:number = 0 // private dronesRoot: Node | null = null; // private monstersRoot: Node | null = null; onLoad() { DroneManager.Instance = this; // 创建管理节点 // this.dronesRoot = new Node('Drones'); // this.node.addChild(this.dronesRoot); // this.monstersRoot = new Node('Monsters'); // this.node.addChild(this.monstersRoot); // // 测试:生成一些怪物 // this.spawnTestMonsters(); } // 生成测试怪物 // private spawnTestMonsters() { // for (let i = 0; i < 5; i++) { // const monster = instantiate(this.monsterPrefab); // this.monstersRoot?.addChild(monster); // // 随机位置,主要在屏幕右侧 // const x = 500 + Math.random() * 300; // const y = 100 + Math.random() * 520; // monster.setPosition(x, y, 0); // } // } // update(deltaTime: number) { // // 依次发射无人机 // if (this.spawnedCount < this.droneCount) { // this.spawnTimer += deltaTime; // if (this.spawnTimer >= this.spawnInterval) { // this.spawnTimer = 0; // this.spawnDrone(); // this.spawnedCount++; // } // } // } // 发射无人机 public spawnDrone() { const droneNode = instantiate(this.dronePrefab); this.node.addChild(droneNode); //droneNode.setPosition(this.spawnPoint); // 初始化无人机,设置不同起始角度避免重叠 const drone = droneNode.getComponent(Drone); if (drone) { const startAngle = 135//(this.spawnedCount / this.droneCount) * Math.PI * 2; drone.init(this.orbitCenter, this.orbitA, this.orbitB, startAngle); } } /**无人机发射子弹 */ droneLaunchBullet(weaponId:number){ // console.log("无人机发射子弹"); //武器数量(无人机) // this.droneCount = weaponCount this.node.children.forEach((child) => { let drone = child.getComponent(Drone) if(drone){ drone.attackTarget(weaponId) } }); } }