FxAIBeelineBulletLogic.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. private Vector3 endPos;
  16. private Vector3 dir;
  17. protected override void ProInit()
  18. {
  19. UnRegister = gameObject.OnTriggerEnterEvent(OnTriggerEnterEvent);
  20. if (isUseCustomTargetEndPos)
  21. {
  22. endPos = TimeLineEventParticleLogicBasic.customizePos[
  23. customTargetEndPosIndex];
  24. }
  25. else
  26. {
  27. endPos = AttTarget.GetSpecialDotInfo("hitpos").GetWorlPos();
  28. }
  29. endPos = new Vector3(endPos.x, CurrPos.y, endPos.z);
  30. dir = (endPos - CurrPos).normalized;
  31. gameObject.transform.rotation = Quaternion.LookRotation(dir);
  32. }
  33. protected void OnTriggerEnterEvent(Collider collision)
  34. {
  35. HeroEntityMono heroEntityMono = collision.gameObject.GetComponent<HeroEntityMono>();
  36. if (heroEntityMono == null)
  37. {
  38. return;
  39. }
  40. CombatHeroEntity target = heroEntityMono.combatHeroEntity;
  41. if (target.IsEnemy == CombatHeroEntity.IsEnemy)
  42. {
  43. return;
  44. }
  45. ITimeLineTriggerEvent timeLineTriggerEvent =
  46. TimeLineEventParticleLogicBasic.ITimeLineTriggerEntity as ITimeLineTriggerEvent;
  47. if (timeLineTriggerEvent != null)
  48. {
  49. timeLineTriggerEvent.TimeLineTrigger(TimeLineEventParticleLogicBasic.TimeLineEventLogicGroup.groupName,
  50. target.GetMainHotPoin<ILifetCycleHitPoint>(), this, triggerData);
  51. if (!string.IsNullOrEmpty(hitFxName))
  52. {
  53. CombatController.currActiveCombat.GameTimeLineParticleFactory.CreateParticle(hitFxName,
  54. collision.ClosestPoint(gameObject.transform.position), null, false, null, null);
  55. }
  56. AudioManager.Instance.PlayAudio(hitAudioName, false);
  57. if (!isPenetrate)
  58. {
  59. Dispose();
  60. }
  61. }
  62. }
  63. protected override void ProCombatUpdate(float time)
  64. {
  65. Vector3 lastPos = _currPos;
  66. Vector3 movePos = dir * speed * time;
  67. _currPos += movePos;
  68. gameObject.transform.position = _currPos;
  69. if (Vector3.SqrMagnitude(_currPos - startPos) > 200)
  70. {
  71. Dispose();
  72. }
  73. }
  74. protected override void ProDispose()
  75. {
  76. if (UnRegister != null)
  77. {
  78. UnRegister.UnRegister();
  79. }
  80. UnRegister = null;
  81. }
  82. }
  83. }