FxNavigationLogic.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using Common.Combat.FxAILogic;
  4. using Core.Audio;
  5. using Core.Triiger;
  6. using GameLogic.Combat.CombatTool;
  7. using GameLogic.Combat.Hero;
  8. using UnityEngine;
  9. using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventinterface;
  10. [AddComponentMenu("特效脚本/弹道/导航型子弹")]
  11. public class FxNavigationLogic : FxAILogicBasic
  12. {
  13. public float speed;
  14. [Header("多少秒后开始导航")] public float delayNavigation;
  15. [Header("最长持续时间")] public float continuedTime=10;
  16. public int PenetrateCount=1;
  17. private IUnRegister UnRegister = null;
  18. private Vector3 endPos;
  19. private Vector3 dir;
  20. private float currTime;
  21. private bool NavigationState;
  22. private float _currNavigationStateTime;
  23. private int _currPenetrateCount;
  24. // private float _NavigationInterval;
  25. protected CombatHeroEntity _currNavigationTargetHero;
  26. protected override void ProInit()
  27. {
  28. UnRegister = gameObject.OnTriggerEnterEvent(this,OnTriggerEnterEvent);
  29. if (isUseCustomTargetEndPos)
  30. {
  31. endPos = TimeLineEventParticleLogicBasic.customizePos[
  32. customTargetEndPosIndex];
  33. }
  34. else
  35. {
  36. endPos = AttTarget.GetSpecialDotInfo("hitpos").GetWorlPos();
  37. }
  38. _currNavigationTargetHero = null;
  39. endPos = new Vector3(endPos.x, CurrPos.y, endPos.z);
  40. dir = (endPos - CurrPos).normalized;
  41. gameObject.transform.rotation = Quaternion.LookRotation(dir);
  42. NavigationState = false;
  43. currTime = 0;
  44. _currNavigationStateTime = 0;
  45. _currPenetrateCount = 0;
  46. }
  47. protected void OnTriggerEnterEvent(Collider collision,ITriggerEntity triggerEntity)
  48. {
  49. HeroEntityMono heroEntityMono = collision.gameObject.GetComponent<HeroEntityMono>();
  50. if (heroEntityMono == null)
  51. {
  52. return;
  53. }
  54. CombatHeroEntity target = heroEntityMono.combatHeroEntity;
  55. if (target.IsEnemy == CombatHeroEntity.IsEnemy)
  56. {
  57. return;
  58. }
  59. if (target.isDie || target.GetMainHotPoin<ILifetCycleHitPoint>() == null)
  60. {
  61. return;
  62. }
  63. ITimeLineTriggerEvent timeLineTriggerEvent =
  64. TimeLineEventParticleLogicBasic.ITimeLineTriggerEntity as ITimeLineTriggerEvent;
  65. if (timeLineTriggerEvent != null)
  66. {
  67. timeLineTriggerEvent.TimeLineTrigger(TimeLineEventParticleLogicBasic.TimeLineEventLogicGroup.groupName,
  68. target.GetMainHotPoin<ILifetCycleHitPoint>(), this, triggerData);
  69. if (!string.IsNullOrEmpty(hitFxName))
  70. {
  71. CombatController.currActiveCombat.GameTimeLineParticleFactory.CreateParticle(hitFxName,
  72. collision.ClosestPoint(gameObject.transform.position), null, false, null, null);
  73. }
  74. _currPenetrateCount++;
  75. AudioManager.Instance.PlayAudio(hitAudioName, false);
  76. NavigationState = false;
  77. _currNavigationStateTime = delayNavigation-0.1f;
  78. if (!isPenetrate||_currPenetrateCount>=PenetrateCount)
  79. {
  80. Dispose();
  81. }
  82. }
  83. }
  84. protected override void ProCombatUpdate(float time)
  85. {
  86. currTime += time;
  87. if (!NavigationState)
  88. {
  89. _currNavigationStateTime += time;
  90. // if (Vector3.SqrMagnitude(_currPos - startPos) > 200)
  91. // {
  92. // Dispose();
  93. // }
  94. if (_currNavigationStateTime > delayNavigation)
  95. {
  96. NavigationState = true;
  97. }
  98. }
  99. else
  100. {
  101. if (_currNavigationTargetHero == null || _currNavigationTargetHero.isDie)
  102. {
  103. FindNavigationTarget();
  104. }
  105. if (_currNavigationTargetHero != null)
  106. {
  107. // Vector3 dotPos= _currNavigationTargetHero.dotPos + new Vector3(0, 0.5f, 0);
  108. // _currPos=
  109. Vector3 newDir = (_currNavigationTargetHero.dotPos - _currPos).normalized;
  110. dir = Vector3.Lerp(dir, newDir, 0.1f);
  111. dir.y = 0;
  112. dir.Normalize();
  113. }
  114. }
  115. Vector3 lastPos = _currPos;
  116. Vector3 movePos = dir * speed * time;
  117. _currPos += movePos;
  118. gameObject.transform.position = _currPos;
  119. gameObject.transform.rotation = Quaternion.LookRotation(dir);
  120. if (currTime > continuedTime)
  121. {
  122. Dispose();
  123. return;
  124. }
  125. }
  126. private void FindNavigationTarget()
  127. {
  128. _currNavigationTargetHero = null;
  129. CombatHeroEntity[] allHero =
  130. CombatController.currActiveCombat.CombatHeroController.GetHero(!CombatHeroEntity.IsEnemy);
  131. if (allHero == null || allHero.Length <= 0)
  132. {
  133. return;
  134. }
  135. int index = CombatCalculateTool.Instance.GetOdd(0, allHero.Length);
  136. _currNavigationTargetHero = allHero[index];
  137. // for (int i = 0; i < allHero.Length; i++)
  138. // {
  139. //
  140. // }
  141. }
  142. protected override void ProDispose()
  143. {
  144. if (UnRegister != null)
  145. {
  146. UnRegister.UnRegister();
  147. }
  148. UnRegister = null;
  149. _currNavigationTargetHero = null;
  150. }
  151. }