FxParabolaBulletLogic.cs 5.6 KB

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