GameObjectPool.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using Fort23.Core;
  2. #if !COMBAT_SERVER
  3. using CombatLibrary.CombatLibrary.CombatCore.GPool;
  4. using UnityEngine;
  5. #endif
  6. namespace Fort23.UTool
  7. {
  8. public class GameObjectPool : IGObjectPoolInterface
  9. {
  10. public string poolObjName { get; set; }
  11. public bool isUse { get; set; }
  12. public bool isDestroy { get; }
  13. #if !COMBAT_SERVER
  14. public AssetHandle AssetHandle { get; set; }
  15. private DelayHide _loopDelayHide;
  16. public GameObject own
  17. {
  18. get { return _own; }
  19. }
  20. private GameObject _own;
  21. public TimerEntity DestroyTimer { get; set; }
  22. #endif
  23. public void SetPosition(Vector3 pos)
  24. {
  25. _pos = pos;
  26. #if !COMBAT_SERVER
  27. _own.transform.position = pos;
  28. #endif
  29. }
  30. public void SetScale(Vector3 scale)
  31. {
  32. _scale = scale;
  33. #if !COMBAT_SERVER
  34. _own.transform.localScale = scale;
  35. #endif
  36. }
  37. public void SetRotation(Vector3 rotation)
  38. {
  39. _rotation = rotation;
  40. #if !COMBAT_SERVER
  41. _own.transform.eulerAngles = rotation;
  42. #endif
  43. }
  44. protected Vector3 _pos;
  45. protected Vector3 _scale;
  46. protected Vector3 _rotation;
  47. public Vector3 GetPosition()
  48. {
  49. return _pos;
  50. }
  51. public Vector3 GetScale()
  52. {
  53. return _scale;
  54. }
  55. public Vector3 GettRotation()
  56. {
  57. return _rotation;
  58. }
  59. public void SetActive(bool isActive)
  60. {
  61. #if !COMBAT_SERVER
  62. _own.SetActive(isActive);
  63. #endif
  64. }
  65. public async CTask DelayHide()
  66. {
  67. #if !COMBAT_SERVER
  68. if (_loopDelayHide != null)
  69. {
  70. await TimerComponent.Instance.WaitAsync((int) (_loopDelayHide.delayTime * 1000));
  71. }
  72. #endif
  73. }
  74. public virtual void ResetData()
  75. {
  76. #if !COMBAT_SERVER
  77. own.transform.SetParent(null);
  78. #endif
  79. }
  80. public virtual void ActiveObj()
  81. {
  82. #if !COMBAT_SERVER
  83. _loopDelayHide = own.GetComponent<DelayHide>();
  84. own.SetActive(true);
  85. #endif
  86. }
  87. public virtual void DormancyObj()
  88. {
  89. #if !COMBAT_SERVER
  90. own.SetActive(false);
  91. #endif
  92. }
  93. public virtual void DestroyObj()
  94. {
  95. #if !COMBAT_SERVER
  96. AssetHandle?.Release();
  97. #endif
  98. }
  99. #if !COMBAT_SERVER
  100. public virtual void SetGameObject(GameObject gameObject)
  101. {
  102. _own = gameObject;
  103. }
  104. #endif
  105. public virtual void Preset()
  106. {
  107. }
  108. public virtual void Dispose()
  109. {
  110. #if !COMBAT_SERVER
  111. _own = null;
  112. #endif
  113. }
  114. }
  115. }