CombatEquipFallManager.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. using System.Collections.Generic;
  2. using Common.Utility.CombatEvent;
  3. using Core.Utility;
  4. using Fort23.Core;
  5. using Fort23.Mono;
  6. using Fort23.UTool;
  7. using GameLogic.Combat.CombatTool;
  8. using UnityEngine;
  9. using Utility;
  10. namespace GameLogic.CombatScenesTool
  11. {
  12. public class CombatEquipFallManager : Singleton<CombatEquipFallManager>
  13. {
  14. private Transform herobagTran;
  15. public Animator BagAnimator;
  16. public BetterList<EquipFallObject> allEquipFall = new BetterList<EquipFallObject>();
  17. public class EquipFallObject : CObject
  18. {
  19. private GameObjectPool GameObjectPool;
  20. private Parabola3DPath Parabola3DPath;
  21. private float _currTime;
  22. private int stateIndex;
  23. private float _addTime;
  24. public EquipFallObjectMono EquipFallObjectMono;
  25. public float waitTime;
  26. public void Init(GameObjectPool GameObjectPool, Parabola3DPath Parabola3DPath, float waitTime = 2f)
  27. {
  28. this.GameObjectPool = GameObjectPool;
  29. this.Parabola3DPath = Parabola3DPath;
  30. this.waitTime = waitTime;
  31. _addTime = 1.0f / Parabola3DPath.totalFlightTime;
  32. EquipFallObjectMono = GameObjectPool.own.GetComponent<EquipFallObjectMono>();
  33. EquipFallObjectMono.idleObject.SetActive(false);
  34. }
  35. public override void Dispose()
  36. {
  37. }
  38. public override void ActiveObj()
  39. {
  40. }
  41. public override void DormancyObj()
  42. {
  43. GObjectPool.Instance.Recycle(GameObjectPool);
  44. GameObjectPool = null;
  45. CObjectPool.Instance.Recycle(Parabola3DPath);
  46. _currTime = 0;
  47. stateIndex = 0;
  48. }
  49. public void Update(float t)
  50. {
  51. if (stateIndex == 0)
  52. {
  53. _currTime += t * _addTime * 2;
  54. Vector3 pos = Parabola3DPath.GetPositionAtTime(_currTime);
  55. GameObjectPool.own.transform.position = pos;
  56. if (_currTime > 1)
  57. {
  58. EquipFallObjectMono.idleObject.SetActive(true);
  59. stateIndex = 1;
  60. _currTime = 0;
  61. }
  62. }
  63. else if (stateIndex == 1)
  64. {
  65. _currTime += t;
  66. if (_currTime > waitTime)
  67. {
  68. stateIndex = 2;
  69. _currTime = 0;
  70. }
  71. }
  72. else if (stateIndex == 2)
  73. {
  74. EquipFallObjectMono.idleObject.SetActive(false);
  75. _currTime += t;
  76. Vector3 pos = CombatEquipFallManager.Instance.GetUIPos();
  77. var position = GameObjectPool.own.transform.position;
  78. float d = Vector3.SqrMagnitude(position - pos);
  79. float addTime = 1.0f / (d / 64);
  80. position = Vector3.Lerp(position,
  81. pos, addTime * t * 3f);
  82. GameObjectPool.own.transform.position = position;
  83. if (d < 0.3f)
  84. {
  85. if (Instance.BagAnimator != null)
  86. {
  87. Instance.BagAnimator.Play("HeroBags_pick");
  88. }
  89. CombatEquipFallManager.Instance.allEquipFall.Remove(this);
  90. CObjectPool.Instance.Recycle(this);
  91. }
  92. }
  93. }
  94. }
  95. public Vector3 GetUIPos()
  96. {
  97. if (herobagTran == null)
  98. {
  99. }
  100. Vector3 pos = UIManager.Instance.UIWorldToWorld(herobagTran.position);
  101. return pos;
  102. }
  103. public void Init()
  104. {
  105. StaticUpdater.Instance.AddRenderUpdateCallBack(Update);
  106. EventManager.Instance.AddEventListener(CustomEventType.Combat_EquipFall, Combat_EquipFall);
  107. }
  108. protected void Combat_EquipFall(IEventData ievetEquia)
  109. {
  110. if (ievetEquia == null)
  111. {
  112. return;
  113. }
  114. Combat_EquipFallEventData combatEquipFallEventData = ievetEquia as Combat_EquipFallEventData;
  115. Fall(combatEquipFallEventData.fallEquip, combatEquipFallEventData.startPos_WorldPos, combatEquipFallEventData.waitTime);
  116. }
  117. public override void Dispose()
  118. {
  119. StaticUpdater.Instance.RemoveRenderUpdateCallBack(Update);
  120. EventManager.Instance.RemoveEventListener(CustomEventType.Combat_EquipFall, Combat_EquipFall);
  121. }
  122. public void Fall(string[] allEquip, Vector3 worldPos, float waitTime = 2f)
  123. {
  124. if (allEquip == null)
  125. {
  126. return;
  127. }
  128. for (int i = 0; i < allEquip.Length; i++)
  129. {
  130. GObjectPool.Instance.FetchAsync<GameObjectPool>(allEquip[i], delegate(GameObjectPool pool)
  131. {
  132. EquipFallObject equipFallObject = CObjectPool.Instance.Fetch<EquipFallObject>();
  133. // equipFallObject.GameObjectPool = pool;
  134. Parabola3DPath parabolaPath = CObjectPool.Instance.Fetch<Parabola3DPath>();
  135. parabolaPath.addY = 3;
  136. Vector3 startPos = worldPos;
  137. float x = Random.Range(-2f, 2f);
  138. float z = Random.Range(-2f, 2f);
  139. Vector3 endPos = startPos + new Vector3(x, 0, z);
  140. parabolaPath.SetPos(startPos, endPos);
  141. pool.own.transform.position = startPos;
  142. if (pool == null)
  143. {
  144. TrailRenderer[] _trailRenderers= pool.own.transform.GetComponentsInChildren<TrailRenderer>(false);
  145. if (_trailRenderers != null)
  146. {
  147. for (int j = 0; j < _trailRenderers.Length; j++)
  148. {
  149. _trailRenderers[i].Clear();
  150. }
  151. }
  152. }
  153. // equipFallObject.Parabola3DPath = parabolaPath;
  154. equipFallObject.Init(pool, parabolaPath, waitTime);
  155. allEquipFall.Add(equipFallObject);
  156. });
  157. }
  158. }
  159. public void Update()
  160. {
  161. for (int i = 0; i < allEquipFall.Count; i++)
  162. {
  163. allEquipFall[i].Update(Time.deltaTime);
  164. }
  165. }
  166. }
  167. }