GObjectPoolBasic.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. using Fort23.Core;
  2. using Fort23.UTool;
  3. #if !COMBAT_SERVER
  4. using UnityEngine;
  5. #endif
  6. namespace Fort23.UTool
  7. {
  8. /// <summary>
  9. /// 基础的池子
  10. /// </summary>
  11. public class GObjectPoolBasic : IGObjectPoolInterface
  12. {
  13. protected Vector3 _pos;
  14. protected Vector3 _scale;
  15. protected Vector3 _rotation;
  16. #if !COMBAT_SERVER
  17. public Transform transform
  18. {
  19. get
  20. {
  21. if (own == null)
  22. {
  23. return null;
  24. }
  25. return own.transform;
  26. }
  27. }
  28. public GameObject gameObject
  29. {
  30. get { return own; }
  31. }
  32. public GameObject own
  33. {
  34. get { return _own; }
  35. }
  36. private GameObject _own;
  37. public AssetHandle AssetHandle { get; set; }
  38. private DelayHide delayHide;
  39. public TimerEntity DestroyTimer { get; set; }
  40. #endif
  41. public string poolObjName { get; set; }
  42. public bool isUse { get; set; }
  43. public bool isDestroy { get; }
  44. public virtual void ResetData()
  45. {
  46. ProResetData();
  47. }
  48. public virtual void ActiveObj()
  49. {
  50. #if !COMBAT_SERVER
  51. own.SetActive(true);
  52. #endif
  53. ProActiveObj();
  54. }
  55. public virtual async CTask DelayHide()
  56. {
  57. #if !COMBAT_SERVER
  58. if (own != null && delayHide != null)
  59. {
  60. await TimerComponent.Instance.WaitAsync((int)(delayHide.delayTime * 1000));
  61. }
  62. #endif
  63. }
  64. public virtual void DormancyObj()
  65. {
  66. ProDormancyObj();
  67. #if !COMBAT_SERVER
  68. own.SetActive(false);
  69. #endif
  70. }
  71. public void SetPosition(Vector3 pos)
  72. {
  73. _pos = pos;
  74. #if !COMBAT_SERVER
  75. if (_own != null)
  76. {
  77. _own.transform.position = pos;
  78. }
  79. #endif
  80. }
  81. public void SetScale(Vector3 scale)
  82. {
  83. _scale = scale;
  84. #if !COMBAT_SERVER
  85. if (_own != null)
  86. {
  87. _own.transform.localScale = scale;
  88. }
  89. #endif
  90. }
  91. #if !COMBAT_SERVER
  92. public void SetParent(Transform root)
  93. {
  94. if (_own != null)
  95. {
  96. _own.transform.SetParent(root);
  97. }
  98. }
  99. #endif
  100. public void SetRotation(Vector3 rotation)
  101. {
  102. _rotation = rotation;
  103. #if !COMBAT_SERVER
  104. if (_own != null)
  105. {
  106. _own.transform.eulerAngles = rotation;
  107. }
  108. #endif
  109. }
  110. public Vector3 GetPosition()
  111. {
  112. return _pos;
  113. }
  114. public Vector3 GetScale()
  115. {
  116. return _scale;
  117. }
  118. public Vector3 GettRotation()
  119. {
  120. return _rotation;
  121. }
  122. public void SetActive(bool isActive)
  123. {
  124. #if !COMBAT_SERVER
  125. _own.SetActive(isActive);
  126. #endif
  127. }
  128. public virtual void DestroyObj()
  129. {
  130. #if !COMBAT_SERVER
  131. AssetHandle?.Release();
  132. #endif
  133. ProOnDestroy();
  134. #if !COMBAT_SERVER
  135. _own = null;
  136. #endif
  137. }
  138. #if !COMBAT_SERVER
  139. public void SetGameObject(GameObject gameObject)
  140. {
  141. _own = gameObject;
  142. delayHide = own.GetComponent<DelayHide>();
  143. }
  144. #endif
  145. public T GetComponent<T>()
  146. {
  147. #if !COMBAT_SERVER
  148. if (_own != null)
  149. {
  150. return _own.GetComponent<T>();
  151. }
  152. return default;
  153. #endif
  154. return default;
  155. }
  156. public virtual void Dispose()
  157. {
  158. }
  159. protected virtual void ProResetData()
  160. {
  161. //gameObject.SetActive(true);
  162. }
  163. protected virtual void ProOnDestroy()
  164. {
  165. }
  166. protected virtual void ProDormancyObj()
  167. {
  168. //gameObject.SetActive(true);
  169. }
  170. protected virtual void ProActiveObj()
  171. {
  172. }
  173. public virtual void Preset()
  174. {
  175. }
  176. }
  177. }