NavMeshAgentControlMixerBehaviour.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.Playables;
  4. using UnityEngine.Timeline;
  5. using UnityEngine.AI;
  6. public class NavMeshAgentControlMixerBehaviour : PlayableBehaviour
  7. {
  8. public override void ProcessFrame(Playable playable, FrameData info, object playerData)
  9. {
  10. NavMeshAgent trackBinding = playerData as NavMeshAgent;
  11. if (!trackBinding)
  12. return;
  13. int inputCount = playable.GetInputCount();
  14. for (int i = 0; i < inputCount; i++)
  15. {
  16. float inputWeight = playable.GetInputWeight(i);
  17. ScriptPlayable<NavMeshAgentControlBehaviour> inputPlayable = (ScriptPlayable<NavMeshAgentControlBehaviour>)playable.GetInput(i);
  18. NavMeshAgentControlBehaviour input = inputPlayable.GetBehaviour();
  19. if (inputWeight > 0.5f && !input.destinationSet && input.destination)
  20. {
  21. if (!trackBinding.isOnNavMesh)
  22. continue;
  23. trackBinding.SetDestination (input.destination.position);
  24. input.destinationSet = true;
  25. }
  26. }
  27. }
  28. }