CombatEquipFallManager.cs 5.2 KB

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