CombatHeroMoveState.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using Animancer;
  2. using Core.Event.Event;
  3. using Fort23.Core;
  4. using GameLogic.Combat.CombatTool;
  5. using OfficeOpenXml.FormulaParsing.Excel.Functions.Logical;
  6. using UnityEngine;
  7. using UnityEngine.AI;
  8. namespace GameLogic.Combat.Hero.State
  9. {
  10. public class CombatHeroMoveState : CombatHeroStateBasic
  11. {
  12. protected Vector3 lasetTaregtPoint;
  13. protected Vector3 lastMovePoint;
  14. protected HeroPlayStateInfoBasic _transitionAsset;
  15. protected bool isStop;
  16. public CombatHeroMoveState(CombatHeroEntity combatHeroEntity) : base(combatHeroEntity)
  17. {
  18. }
  19. public override bool IsUpdateLockTarget()
  20. {
  21. return false;
  22. }
  23. protected override void ProEnter()
  24. {
  25. EventManager.Instance.AddEventListener(CustomEventType.RefreshFull, RefreshFull);
  26. Start();
  27. }
  28. protected void Start()
  29. {
  30. lasetTaregtPoint = new Vector3(999999, 99999, 99999);
  31. _transitionAsset = combatHeroEntity.combatHeroAnimtion.Play("run");
  32. }
  33. protected void RefreshFull(IEventData ieEventData)
  34. {
  35. RefreshFullEventData data = (RefreshFullEventData)ieEventData;
  36. if (data.isFullShow && !isStop)
  37. {
  38. isStop = true;
  39. }
  40. else if (isStop)
  41. {
  42. Start();
  43. isStop = false;
  44. }
  45. }
  46. protected override void ProExit()
  47. {
  48. EventManager.Instance.RemoveEventListener(CustomEventType.RefreshFull, RefreshFull);
  49. // combatHeroEntity.CombatAIBasic.NavMeshAgent.acceleration = 0;
  50. }
  51. protected void SetNewPath(Vector3 taregtPos)
  52. {
  53. lastMovePoint = combatHeroEntity.dotPos;
  54. lasetTaregtPoint = taregtPos;
  55. }
  56. protected override void ProUpdate(float t)
  57. {
  58. if (combatHeroEntity.CombatAIBasic.currFocusTarget == null)
  59. {
  60. combatHeroEntity.CombatAIBasic.ChangeState(CombatHeroStateType.idle);
  61. return;
  62. }
  63. if (combatHeroEntity.CombatHeroSkillControl.CanReleaseSkill() != null)
  64. {
  65. combatHeroEntity.CombatAIBasic.ChangeState(CombatHeroStateType.att);
  66. return;
  67. }
  68. Vector3 targetPos = combatHeroEntity.CombatAIBasic.currFocusTarget.dotPos;
  69. Vector3 myPos = combatHeroEntity.dotPos;
  70. float dis = combatHeroEntity.CurrCombatHeroInfo.maxDisTo;
  71. if (combatHeroEntity.CombatAIBasic.currFocusTarget is BannerHero)
  72. {
  73. dis = 1;
  74. }
  75. if (Vector3.SqrMagnitude(targetPos - myPos) >
  76. dis)
  77. {
  78. if (Vector3.SqrMagnitude(lasetTaregtPoint - targetPos) > 1)
  79. {
  80. // SetNewPath(targetPos);
  81. }
  82. }
  83. else
  84. {
  85. combatHeroEntity.CombatAIBasic.ChangeState(CombatHeroStateType.idle);
  86. return;
  87. }
  88. }
  89. }
  90. }