GFGSpawner.cs 850 B

1234567891011121314151617181920212223242526272829303132
  1. using UniFramework.Pooling;
  2. using UnityEngine;
  3. using System.Collections.Generic;
  4. namespace GFGGame
  5. {
  6. public class GFGSpawner
  7. {
  8. private Spawner _entitySpawner;
  9. private Dictionary<string, bool> poolCreated = new Dictionary<string, bool>();
  10. public void Init()
  11. {
  12. // 创建游戏对象发生器
  13. _entitySpawner = UniPooling.CreateSpawner(VersionController.DefaultPackage);
  14. }
  15. public GameObject SpawnSync(string resPath)
  16. {
  17. poolCreated.TryGetValue(resPath, out bool created);
  18. if (!created)
  19. {
  20. // 创建游戏对象池
  21. _entitySpawner.CreateGameObjectPoolAsync(resPath);
  22. }
  23. var handle = _entitySpawner.SpawnSync(resPath);
  24. return handle.GameObj;
  25. }
  26. }
  27. }