CurvedUIPool.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class CurvedUIPool : MonoBehaviour
  5. {
  6. private static CurvedUIPool instance = null;
  7. //共有的唯一的,全局访问点
  8. public static CurvedUIPool Instance
  9. {
  10. get
  11. {
  12. if (instance == null)
  13. { //查找场景中是否已经存在单例
  14. instance = GameObject.FindObjectOfType<CurvedUIPool>();
  15. if (instance == null)
  16. { //创建游戏对象然后绑定单例脚本
  17. GameObject go = new GameObject("CurvedUIPool");
  18. instance = go.AddComponent<CurvedUIPool>();
  19. }
  20. }
  21. return instance;
  22. }
  23. }
  24. private void Awake()
  25. { //防止存在多个单例
  26. if (instance == null)
  27. instance = this;
  28. else
  29. Destroy(gameObject);
  30. }
  31. public Transform _poolTrans;
  32. public bool isPlayCurvedLoadAni = true;
  33. public CurvedUIBaseController _cuiBasePrefab;
  34. public List<CurvedUIBaseController> _cuiBaseControllerPools = new List<CurvedUIBaseController>();
  35. public CurvedUIBaseController GetCUIBaseController()
  36. {
  37. if (_cuiBaseControllerPools.Count > 0)
  38. {
  39. CurvedUIBaseController get_CuiBase = _cuiBaseControllerPools[0];
  40. _cuiBaseControllerPools.Remove(get_CuiBase);
  41. return get_CuiBase;
  42. }
  43. else
  44. {
  45. CurvedUIBaseController item = GameObject.Instantiate(_cuiBasePrefab);
  46. item.transform.parent = _poolTrans;
  47. item.gameObject.SetActive(true);
  48. item.InitCurvedOpenState(false);
  49. return item;
  50. }
  51. }
  52. public void PutCUIBaseController(CurvedUIBaseController cuiBase)
  53. {
  54. if (!_cuiBaseControllerPools.Contains(cuiBase))
  55. {
  56. _cuiBaseControllerPools.Add(cuiBase);
  57. }
  58. cuiBase.InitCurvedOpenState(false);
  59. }
  60. }