MeshPool.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*************************************************************************
  2. * Copyright © 2018-2023 Liwen All rights reserved.
  3. *------------------------------------------------------------------------
  4. * File : TileObjectPool.cs
  5. * Description : PagedLod tile object pool.
  6. *------------------------------------------------------------------------
  7. * Author : Liwen
  8. * Version : 1.0.0
  9. * Date : 1/5/2019
  10. * Description : Initial development version.
  11. *************************************************************************/
  12. using System.Collections;
  13. using System.Collections.Generic;
  14. using UnityEngine;
  15. namespace AIPagedLod
  16. {
  17. public class MeshPool : MonoBehaviour
  18. {
  19. public static MeshPool mInstance = null;
  20. private List<GameObject> mMeshObjectList = new List<GameObject>();
  21. private int mCreateMeshCount = 0;
  22. void Awake()
  23. {
  24. mInstance = this;
  25. }
  26. public void PushMeshObject(GameObject tileObj)
  27. {
  28. tileObj.SetActive(false);
  29. mMeshObjectList.Add(tileObj);
  30. tileObj.transform.parent = transform;
  31. }
  32. public GameObject GetMeshObject()
  33. {
  34. if (mMeshObjectList.Count > 0)
  35. {
  36. GameObject targetObj = mMeshObjectList[0];
  37. mMeshObjectList.RemoveAt(0);
  38. return targetObj;
  39. }
  40. mCreateMeshCount++;
  41. return null;
  42. }
  43. }
  44. }