import { _decorator, Component, instantiate, Node, Prefab, resources, UITransform } from 'cc'; import { PropBase } from './Prop/Base/PropBase'; import { ObjectPoolManager } from './Prop/ObjectPoolManager'; const { ccclass, property } = _decorator; @ccclass('AutoBuild') export class AutoBuild extends Component { protected onLoad(): void { ObjectPoolManager.getInstance().initializePools().then((ok) => { if (ok) { console.log('初始化成功'); this.schedule(() => { this.BuildOnce(FloorType.diban) }, 0.1) } }); } BuildOnce(Type: FloorType) { let Node = ObjectPoolManager.getInstance().getNodeFromPool(Type, this.node) if (!Node) { console.error('没有找到节点') return } // this.InitNode(Node) } ClerarNode() { } InitNode(node: Node) { this.node.addChild(node); let size = this.node.getComponent(UITransform).contentSize let width = (size.width - (node.getComponent(UITransform).contentSize.width * 1.33)) / 2; let height = -size.height / 2; height -= 200; const x = this.getRandomNumber(-width, width); const y = height node.setPosition(x, y, 0); node.getComponent(PropBase).UpSpeed = 20 } getRandomNumber(min: number, max: number): number { return Math.floor(Math.random() * (max - min + 1)) + min; } } export enum FloorType { diban = 'diban',//预制体的名称 dicin = 'dici', }