FxAIBeelineBulletLogic.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. using Core.Triiger;
  3. using GameLogic.Combat.CombatTool;
  4. using GameLogic.Combat.Hero;
  5. using UnityEngine;
  6. using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventinterface;
  7. namespace Common.Combat.FxAILogic
  8. {
  9. public class FxAIBeelineBulletLogic : FxAILogicBasic
  10. {
  11. public float speed;
  12. private IUnRegister UnRegister = null;
  13. private Vector3 endPos;
  14. private Vector3 dir;
  15. protected override void ProInit()
  16. {
  17. UnRegister = gameObject.OnTriggerEnterEvent(OnTriggerEnterEvent);
  18. if (isUseCustomTargetEndPos)
  19. {
  20. endPos = TimeLineEventParticleLogicBasic.customizePos[
  21. customTargetEndPosIndex];
  22. }
  23. else
  24. {
  25. endPos = AttTarget.GetSpecialDotInfo("hitpos").GetWorlPos();
  26. }
  27. endPos = new Vector3(endPos.x, CurrPos.y, endPos.z);
  28. dir = (endPos - CurrPos).normalized;
  29. gameObject.transform.rotation = Quaternion.LookRotation(dir);
  30. }
  31. protected void OnTriggerEnterEvent(Collider collision)
  32. {
  33. HeroEntityMono heroEntityMono = collision.gameObject.GetComponent<HeroEntityMono>();
  34. if (heroEntityMono == null)
  35. {
  36. return;
  37. }
  38. CombatHeroEntity target = heroEntityMono.combatHeroEntity;
  39. if (target.IsEnemy == CombatHeroEntity.IsEnemy)
  40. {
  41. return;
  42. }
  43. ITimeLineTriggerEvent timeLineTriggerEvent =
  44. TimeLineEventParticleLogicBasic.ITimeLineTriggerEntity as ITimeLineTriggerEvent;
  45. if (timeLineTriggerEvent != null)
  46. {
  47. timeLineTriggerEvent.TimeLineTrigger(TimeLineEventParticleLogicBasic.TimeLineEventLogicGroup.groupName,
  48. target.GetMainHotPoin<ILifetCycleHitPoint>(), this, triggerData);
  49. if (!string.IsNullOrEmpty(hitFxName))
  50. {
  51. CombatController.currActiveCombat.GameTimeLineParticleFactory.CreateParticle(hitFxName,
  52. collision.ClosestPoint(gameObject.transform.position), null, false, null, null);
  53. }
  54. if (!isPenetrate)
  55. {
  56. Dispose();
  57. }
  58. }
  59. }
  60. protected override void ProCombatUpdate(float time)
  61. {
  62. Vector3 lastPos = _currPos;
  63. Vector3 movePos = dir * speed * time;
  64. _currPos += movePos;
  65. gameObject.transform.position = _currPos;
  66. if (Vector3.SqrMagnitude(_currPos - startPos) > 200)
  67. {
  68. Dispose();
  69. }
  70. }
  71. protected override void ProDispose()
  72. {
  73. if (UnRegister != null)
  74. {
  75. UnRegister.UnRegister();
  76. }
  77. UnRegister = null;
  78. }
  79. }
  80. }