RepelledStatusState.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using UnityEngine;
  2. using UnityEngine.AI;
  3. namespace GameLogic.Combat.Hero.SubStatus
  4. {
  5. public class RepelledStatusState : SubStatusBasic
  6. {
  7. private float repelledDis;
  8. private float speed;
  9. private System.Action callBack;
  10. private float _currMoveDis;
  11. private Vector3 dir;
  12. public RepelledStatusState(Vector3 dir, float repelledDis, float speed, System.Action callBack)
  13. {
  14. this.repelledDis = repelledDis;
  15. this.speed = speed;
  16. this.callBack = callBack;
  17. this.dir = dir.normalized;
  18. _currMoveDis = 0;
  19. }
  20. public override string IsGetStateName()
  21. {
  22. return CombatHeroStateType.NullState;
  23. }
  24. protected override void ProDispose()
  25. {
  26. CombatHeroEntity.CombatAIBasic.stateControl.ChangeState(CombatHeroStateType.idle);
  27. }
  28. protected override void ProUpdate(float t)
  29. {
  30. float addDis = speed * t;
  31. Vector3 pos= CombatHeroEntity.combatHeroGameObject.transform.position + dir * addDis;
  32. CombatHeroEntity.CombatAIBasic.NavMeshAgent.Raycast(pos,
  33. out NavMeshHit hit);
  34. if (!hit.hit)
  35. {
  36. CombatHeroEntity.combatHeroGameObject.transform.position = pos;
  37. }
  38. else
  39. {
  40. callBack?.Invoke();
  41. Dispose();
  42. return;
  43. }
  44. _currMoveDis += addDis;
  45. if (_currMoveDis >= repelledDis)
  46. {
  47. callBack?.Invoke();
  48. Dispose();
  49. }
  50. }
  51. }
  52. }