CombatEquipFallManager.cs 4.6 KB

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