CombatHeroMoveState.cs 3.1 KB

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