NavMeshAgentTimeline.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using UnityEngine;
  2. namespace Chronos
  3. {
  4. public class NavMeshAgentTimeline : ComponentTimeline<UnityEngine.AI.NavMeshAgent>
  5. {
  6. private float _speed;
  7. /// <summary>
  8. /// The speed that is applied to the agent before time effects. Use this property instead of NavMeshAgent.speed, which will be overwritten by the timeline at runtime.
  9. /// </summary>
  10. public float speed
  11. {
  12. get { return _speed; }
  13. set
  14. {
  15. _speed = value;
  16. AdjustProperties();
  17. }
  18. }
  19. private float _angularSpeed;
  20. /// <summary>
  21. /// The angular speed that is applied to the agent before time effects. Use this property instead of NavMeshAgent.angularSpeed, which will be overwritten by the timeline at runtime.
  22. /// </summary>
  23. public float angularSpeed
  24. {
  25. get { return _angularSpeed; }
  26. set
  27. {
  28. _angularSpeed = value;
  29. AdjustProperties();
  30. }
  31. }
  32. public NavMeshAgentTimeline(Timeline timeline, UnityEngine.AI.NavMeshAgent component) : base(timeline, component) { }
  33. public override void Update()
  34. {
  35. if (timeline.lastTimeScale > 0 && timeline.timeScale == 0) // Arrived at halt
  36. {
  37. component.velocity = Vector3.zero; // Stop the smoothing
  38. }
  39. }
  40. public override void CopyProperties(UnityEngine.AI.NavMeshAgent source)
  41. {
  42. _speed = source.speed;
  43. _angularSpeed = source.angularSpeed;
  44. }
  45. public override void AdjustProperties(float timeScale)
  46. {
  47. component.speed = speed * timeScale;
  48. component.angularSpeed = angularSpeed * timeScale;
  49. }
  50. }
  51. }