FxParabolaBulletLogic.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. using System.Collections.Generic;
  2. using Core.Audio;
  3. using Core.Triiger;
  4. using GameLogic.Combat.CombatTool;
  5. using GameLogic.Combat.Hero;
  6. using UnityEngine;
  7. using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventinterface;
  8. namespace Common.Combat.FxAILogic
  9. {
  10. [AddComponentMenu("特效脚本/弹道/功法通用弹道")]
  11. public class FxParabolaBulletLogic : FxAILogicBasic
  12. {
  13. public float speed;
  14. private IUnRegister UnRegister = null;
  15. [Header("释放碰撞到地面时结束")] public bool isTriggerGroundEnd;
  16. [Header("碰撞到地面时的特效")] public string GroundHitFxName;
  17. private Vector3 endPos;
  18. private Vector3 dir;
  19. public float maxDis = 20;
  20. protected float maxDisSpr;
  21. // private BesselPath _besselPath;
  22. private float _addTime;
  23. protected Vector3 startDir;
  24. private float dirLerpTime;
  25. protected override void ProInit()
  26. {
  27. maxDisSpr = maxDis * maxDis;
  28. UnRegister = gameObject.OnTriggerEnterEvent(OnTriggerEnterEvent);
  29. if (isUseCustomTargetEndPos)
  30. {
  31. endPos = TimeLineEventParticleLogicBasic.customizePos[
  32. customTargetEndPosIndex];
  33. }
  34. else
  35. {
  36. endPos = AttTarget.GetSpecialDotInfo("hitpos").GetWorlPos();
  37. // endPos = new Vector3(endPos.x, CurrPos.y, endPos.z);
  38. }
  39. startDir = CombatHeroEntity.GameObject.transform.TransformPoint(new Vector3(Mathf.Sign(Random.Range(-1, 1)),
  40. Random.Range(0.1F, 1),
  41. 1));
  42. startDir =( startDir-_currPos).normalized;
  43. dirLerpTime = 0;
  44. // dir = (endPos - CurrPos).normalized;
  45. // gameObject.transform.rotation = Quaternion.LookRotation(dir);
  46. }
  47. void TriggerGround()
  48. {
  49. ITimeLineTriggerEvent timeLineTriggerEvent =
  50. TimeLineEventParticleLogicBasic.ITimeLineTriggerEntity as ITimeLineTriggerEvent;
  51. FinishHit(new Vector3(_currPos.x, 0.5f, _currPos.z), GroundHitFxName);
  52. AudioManager.Instance.PlayAudio(hitAudioName, false);
  53. if (timeLineTriggerEvent != null)
  54. {
  55. timeLineTriggerEvent.TimeLineTriggerGround(
  56. TimeLineEventParticleLogicBasic.TimeLineEventLogicGroup.groupName,
  57. this, triggerData);
  58. }
  59. AudioManager.Instance.PlayAudio(hitAudioName, false);
  60. Dispose();
  61. }
  62. protected void GetTargetPos()
  63. {
  64. if (isUseCustomTargetEndPos)
  65. {
  66. endPos = TimeLineEventParticleLogicBasic.customizePos[
  67. customTargetEndPosIndex];
  68. }
  69. else
  70. {
  71. endPos = AttTarget.GetSpecialDotInfo("hitpos").GetWorlPos();
  72. // endPos = new Vector3(endPos.x, CurrPos.y, endPos.z);
  73. }
  74. }
  75. protected void OnTriggerEnterEvent(Collider collision)
  76. {
  77. ITimeLineTriggerEvent timeLineTriggerEvent =
  78. TimeLineEventParticleLogicBasic.ITimeLineTriggerEntity as ITimeLineTriggerEvent;
  79. if (isTriggerGroundEnd)
  80. {
  81. if (collision.gameObject.CompareTag("dimian"))
  82. {
  83. TriggerGround();
  84. return;
  85. }
  86. }
  87. HeroEntityMono heroEntityMono = collision.gameObject.GetComponent<HeroEntityMono>();
  88. if (heroEntityMono == null)
  89. {
  90. return;
  91. }
  92. CombatHeroEntity target = heroEntityMono.combatHeroEntity;
  93. if (target.IsEnemy == CombatHeroEntity.IsEnemy)
  94. {
  95. return;
  96. }
  97. if (timeLineTriggerEvent != null)
  98. {
  99. timeLineTriggerEvent.TimeLineTrigger(TimeLineEventParticleLogicBasic.TimeLineEventLogicGroup.groupName,
  100. target.GetMainHotPoin<ILifetCycleHitPoint>(), this, triggerData);
  101. if (!string.IsNullOrEmpty(hitFxName))
  102. {
  103. FinishHit(collision.ClosestPoint(gameObject.transform.position), hitFxName);
  104. }
  105. AudioManager.Instance.PlayAudio(hitAudioName, false);
  106. if (!isPenetrate)
  107. {
  108. Dispose();
  109. }
  110. }
  111. }
  112. private void FinishHit(Vector3 pos, string hitFxName)
  113. {
  114. if (!string.IsNullOrEmpty(hitFxName))
  115. {
  116. CombatController.currActiveCombat.GameTimeLineParticleFactory.CreateParticle(hitFxName,
  117. pos, null, false, null, null);
  118. }
  119. }
  120. protected override void ProCombatUpdate(float time)
  121. {
  122. currTime += _addTime * time;
  123. dirLerpTime += time*1.2F;
  124. if (dirLerpTime > 1)
  125. {
  126. dirLerpTime = 1;
  127. }
  128. GetTargetPos();
  129. Vector3 dir = (endPos - _currPos).normalized;
  130. dir = Vector3.Lerp(startDir, dir, dirLerpTime).normalized;
  131. Vector3 lasetPos = _currPos;
  132. _currPos += dir * speed * time;
  133. gameObject.transform.position = _currPos;
  134. gameObject.transform.rotation = Quaternion.LookRotation(dir);
  135. if (Vector3.Distance(endPos, _currPos) < 0.5f)
  136. {
  137. Dispose();
  138. }
  139. // if (currTime >= 1)
  140. // {
  141. // Dispose();
  142. // }
  143. // if (!isTriggerGroundEnd)
  144. // {
  145. // if (Vector3.SqrMagnitude(_currPos - startPos) > maxDisSpr)
  146. // {
  147. // Dispose();
  148. // }
  149. // }
  150. // else
  151. // {
  152. // if (_currPos.y < 0.3f)
  153. // {
  154. // TriggerGround();
  155. // }
  156. // }
  157. }
  158. protected override void ProDispose()
  159. {
  160. if (UnRegister != null)
  161. {
  162. UnRegister.UnRegister();
  163. }
  164. UnRegister = null;
  165. }
  166. }
  167. }