FxAIBeelineBulletLogic.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using System;
  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 FxAIBeelineBulletLogic : 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. protected override void ProInit()
  20. {
  21. UnRegister = gameObject.OnTriggerEnterEvent(OnTriggerEnterEvent);
  22. if (isUseCustomTargetEndPos)
  23. {
  24. endPos = TimeLineEventParticleLogicBasic.customizePos[
  25. customTargetEndPosIndex];
  26. }
  27. else
  28. {
  29. endPos = AttTarget.GetSpecialDotInfo("hitpos").GetWorlPos();
  30. endPos = new Vector3(endPos.x, CurrPos.y, endPos.z);
  31. }
  32. dir = (endPos - CurrPos).normalized;
  33. gameObject.transform.rotation = Quaternion.LookRotation(dir);
  34. }
  35. void TriggerGround()
  36. {
  37. ITimeLineTriggerEvent timeLineTriggerEvent =
  38. TimeLineEventParticleLogicBasic.ITimeLineTriggerEntity as ITimeLineTriggerEvent;
  39. FinishHit(new Vector3(_currPos.x, 0.5f, _currPos.z), GroundHitFxName);
  40. AudioManager.Instance.PlayAudio(hitAudioName, false);
  41. if (timeLineTriggerEvent != null)
  42. {
  43. timeLineTriggerEvent.TimeLineTriggerGround(
  44. TimeLineEventParticleLogicBasic.TimeLineEventLogicGroup.groupName,
  45. this, triggerData);
  46. }
  47. AudioManager.Instance.PlayAudio(hitAudioName, false);
  48. Dispose();
  49. }
  50. protected void OnTriggerEnterEvent(Collider collision)
  51. {
  52. ITimeLineTriggerEvent timeLineTriggerEvent =
  53. TimeLineEventParticleLogicBasic.ITimeLineTriggerEntity as ITimeLineTriggerEvent;
  54. if (isTriggerGroundEnd)
  55. {
  56. if (collision.gameObject.CompareTag("dimian"))
  57. {
  58. TriggerGround();
  59. return;
  60. }
  61. }
  62. HeroEntityMono heroEntityMono = collision.gameObject.GetComponent<HeroEntityMono>();
  63. if (heroEntityMono == null)
  64. {
  65. return;
  66. }
  67. CombatHeroEntity target = heroEntityMono.combatHeroEntity;
  68. if (target.IsEnemy == CombatHeroEntity.IsEnemy)
  69. {
  70. return;
  71. }
  72. if (timeLineTriggerEvent != null)
  73. {
  74. timeLineTriggerEvent.TimeLineTrigger(TimeLineEventParticleLogicBasic.TimeLineEventLogicGroup.groupName,
  75. target.GetMainHotPoin<ILifetCycleHitPoint>(), this, triggerData);
  76. if (!string.IsNullOrEmpty(hitFxName))
  77. {
  78. FinishHit(collision.ClosestPoint(gameObject.transform.position), hitFxName);
  79. }
  80. AudioManager.Instance.PlayAudio(hitAudioName, false);
  81. if (!isPenetrate)
  82. {
  83. Dispose();
  84. }
  85. }
  86. }
  87. private void FinishHit(Vector3 pos, string hitFxName)
  88. {
  89. if (!string.IsNullOrEmpty(hitFxName))
  90. {
  91. CombatController.currActiveCombat.GameTimeLineParticleFactory.CreateParticle(hitFxName,
  92. pos, null, false, null, null);
  93. }
  94. }
  95. protected override void ProCombatUpdate(float time)
  96. {
  97. Vector3 lastPos = _currPos;
  98. Vector3 movePos = dir * speed * time;
  99. _currPos += movePos;
  100. gameObject.transform.position = _currPos;
  101. if (!isTriggerGroundEnd)
  102. {
  103. if (Vector3.SqrMagnitude(_currPos - startPos) > 200)
  104. {
  105. Dispose();
  106. }
  107. }
  108. else
  109. {
  110. if (_currPos.y < 0.3f)
  111. {
  112. TriggerGround();
  113. }
  114. }
  115. }
  116. protected override void ProDispose()
  117. {
  118. if (UnRegister != null)
  119. {
  120. UnRegister.UnRegister();
  121. }
  122. UnRegister = null;
  123. }
  124. }
  125. }