TileObjectPool.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 TileObjectPool : MonoBehaviour
  18. {
  19. public static TileObjectPool mInstance = null;
  20. private List<GameObject> mTileObjectList = new List<GameObject>();
  21. private int mCreateTileCount = 0;
  22. void Awake()
  23. {
  24. mInstance = this;
  25. }
  26. public void PushTileObject(GameObject tileObj)
  27. {
  28. tileObj.SetActive(false);
  29. mTileObjectList.Add(tileObj);
  30. tileObj.transform.parent = transform;
  31. }
  32. public GameObject GetTileObject()
  33. {
  34. if (mTileObjectList.Count > 0)
  35. {
  36. GameObject targetObj = mTileObjectList[0];
  37. mTileObjectList.RemoveAt(0);
  38. return targetObj;
  39. }
  40. mCreateTileCount++;
  41. return null;
  42. }
  43. }
  44. }