ResourcePool.ts 608 B

123456789101112131415161718192021222324
  1. import { _decorator, Prefab, Node, instantiate, NodePool, Vec3 } from "cc";
  2. const { ccclass, property } = _decorator;
  3. @ccclass("ResourcePool")
  4. export class ResourcePool {
  5. private prefab_pool: any = {}
  6. static rp: ResourcePool;
  7. static get instance() {
  8. if (!this.rp) {
  9. this.rp = new ResourcePool();
  10. window["rp"] = this.rp;
  11. }
  12. return this.rp;
  13. }
  14. public set_prefab(name: string, prefab: Prefab): void {
  15. this.prefab_pool[name] = prefab;
  16. }
  17. public get_prefab(name: string): Prefab {
  18. return this.prefab_pool[name];
  19. }
  20. }