CombatEquipFallManager.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using System.Collections.Generic;
  2. using Core.Utility;
  3. using Fort23.Core;
  4. using Fort23.UTool;
  5. using GameLogic.Combat.CombatTool;
  6. using UnityEngine;
  7. using Utility;
  8. namespace GameLogic.CombatScenesTool
  9. {
  10. public class CombatEquipFallManager : Singleton<CombatEquipFallManager>
  11. {
  12. public BetterList<EquipFallObject> allEquipFall = new BetterList<EquipFallObject>();
  13. public class EquipFallObject : CObject
  14. {
  15. private GameObjectPool GameObjectPool;
  16. private Parabola3DPath Parabola3DPath;
  17. private float _currTime;
  18. private int stateIndex;
  19. private float _addTime;
  20. public EquipFallObjectMono EquipFallObjectMono;
  21. public void Init(GameObjectPool GameObjectPool, Parabola3DPath Parabola3DPath)
  22. {
  23. this.GameObjectPool = GameObjectPool;
  24. this.Parabola3DPath = Parabola3DPath;
  25. _addTime = 1.0f / Parabola3DPath.totalFlightTime;
  26. EquipFallObjectMono = GameObjectPool.own.GetComponent<EquipFallObjectMono>();
  27. EquipFallObjectMono.idleObject.SetActive(false);
  28. }
  29. public override void Dispose()
  30. {
  31. }
  32. public override void ActiveObj()
  33. {
  34. }
  35. public override void DormancyObj()
  36. {
  37. GObjectPool.Instance.Recycle(GameObjectPool);
  38. GameObjectPool = null;
  39. CObjectPool.Instance.Recycle(Parabola3DPath);
  40. _currTime = 0;
  41. stateIndex = 0;
  42. }
  43. public void Update(float t)
  44. {
  45. if (stateIndex == 0)
  46. {
  47. _currTime += t * _addTime * 2;
  48. Vector3 pos = Parabola3DPath.GetPositionAtTime(_currTime * Parabola3DPath.totalFlightTime);
  49. GameObjectPool.own.transform.position = pos;
  50. if (_currTime > 1)
  51. {
  52. EquipFallObjectMono.idleObject.SetActive(true);
  53. stateIndex = 1;
  54. _currTime = 0;
  55. }
  56. }
  57. else if (stateIndex == 1)
  58. {
  59. _currTime += t;
  60. if (_currTime > 2)
  61. {
  62. stateIndex = 2;
  63. _currTime = 0;
  64. }
  65. }
  66. else if (stateIndex == 2)
  67. {
  68. EquipFallObjectMono.idleObject.SetActive(false);
  69. _currTime += t;
  70. CombatHeroEntity[] heroEntities =
  71. CombatController.currActiveCombat.CombatHeroController.GetHero(false);
  72. if (heroEntities == null)
  73. {
  74. return;
  75. }
  76. if (heroEntities.Length > 0)
  77. {
  78. Transform heroT = heroEntities[0].combatHeroGameObject.transform;
  79. GameObjectPool.own.transform.position = Vector3.Lerp(GameObjectPool.own.transform.position,
  80. heroT.position, 0.2f);
  81. if (Vector3.SqrMagnitude(GameObjectPool.own.transform.position - heroT.position) < 0.3f)
  82. {
  83. CombatEquipFallManager.Instance.allEquipFall.Remove(this);
  84. CObjectPool.Instance.Recycle(this);
  85. }
  86. }
  87. }
  88. }
  89. }
  90. public CombatEquipFallManager()
  91. {
  92. StaticUpdater.Instance.AddRenderUpdateCallBack(Update);
  93. }
  94. public override void Dispose()
  95. {
  96. StaticUpdater.Instance.RemoveRenderUpdateCallBack(Update);
  97. }
  98. public void Fall(List<string> allEquip, Vector3 worldPos)
  99. {
  100. for (int i = 0; i < allEquip.Count; i++)
  101. {
  102. GObjectPool.Instance.FetchAsync<GameObjectPool>(allEquip[i], delegate(GameObjectPool pool)
  103. {
  104. EquipFallObject equipFallObject = CObjectPool.Instance.Fetch<EquipFallObject>();
  105. // equipFallObject.GameObjectPool = pool;
  106. Parabola3DPath parabolaPath = CObjectPool.Instance.Fetch<Parabola3DPath>();
  107. parabolaPath.addY = 3;
  108. Vector3 startPos = worldPos;
  109. float x = Random.Range(-2f, 2f);
  110. float z = Random.Range(-2f, 2f);
  111. // if (x < 0)
  112. // {
  113. // x = Mathf.Clamp(x, -1, -2.5f);
  114. // }
  115. // else
  116. // {
  117. // x = Mathf.Clamp(x, 1, 2.5f);
  118. // }
  119. //
  120. // if (z < 0)
  121. // {
  122. // z = Mathf.Clamp(z, -1, -2.5f);
  123. // }
  124. // else
  125. // {
  126. // z = Mathf.Clamp(z, 1, 2.5f);
  127. // }
  128. Vector3 endPos = startPos + new Vector3(x, 0, z);
  129. parabolaPath.SetPos(startPos, endPos);
  130. // equipFallObject.Parabola3DPath = parabolaPath;
  131. equipFallObject.Init(pool, parabolaPath);
  132. allEquipFall.Add(equipFallObject);
  133. });
  134. }
  135. }
  136. public void Update()
  137. {
  138. for (int i = 0; i < allEquipFall.Count; i++)
  139. {
  140. allEquipFall[i].Update(Time.deltaTime);
  141. }
  142. }
  143. }
  144. }