No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AgentVelocityTestAfterOffMeshLink.cs 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System.Collections;
  2. using NUnit.Framework;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5. using UnityEngine.TestTools;
  6. namespace Unity.AI.Navigation.Tests
  7. {
  8. [TestFixture]
  9. [Category("RegressionTest")]
  10. [PrebuildSetup("Unity.AI.Navigation.Tests." + nameof(SimpleScene2PlanesNavigationSetup))]
  11. [PostBuildCleanup("Unity.AI.Navigation.Tests." + nameof(SimpleScene2PlanesNavigationSetup))]
  12. class AgentVelocityTestAfterOffMeshLink : OffMeshLinkTestBase
  13. {
  14. readonly string k_SceneName = "OffMeshLinkTwoPlanesScene";
  15. [UnitySetUp]
  16. public IEnumerator UnitySetUp()
  17. {
  18. yield return SceneManager.LoadSceneAsync(k_SceneName, LoadSceneMode.Additive);
  19. yield return null;
  20. SceneManager.SetActiveScene(SceneManager.GetSceneByName(k_SceneName));
  21. }
  22. [UnityTest]
  23. [UnityPlatform(exclude = new[] { RuntimePlatform.OSXServer, RuntimePlatform.WindowsServer, RuntimePlatform.LinuxServer })]
  24. public IEnumerator Agent_AfterTraversingOffMeshLink_HasVelocityAlignedWithTheLink()
  25. {
  26. var link = CreateBiDirectionalLink(true);
  27. m_Agent.transform.position = link.startTransform.position + new Vector3(3, 0, 3);
  28. m_Agent.SetDestination(link.endTransform.position + new Vector3(-3, 0, 3));
  29. yield return null;
  30. while (!m_Agent.isOnOffMeshLink)
  31. yield return null;
  32. while (m_Agent.isOnOffMeshLink)
  33. yield return null;
  34. yield return 0;
  35. var agentMoveDir = m_Agent.velocity;
  36. agentMoveDir.y = 0;
  37. agentMoveDir = agentMoveDir.normalized;
  38. var linkDir = link.endTransform.position - link.startTransform.position;
  39. linkDir.y = 0;
  40. linkDir = linkDir.normalized;
  41. // Get the angle in degrees between the direction vectors.
  42. var angle = Vector3.Angle(linkDir, agentMoveDir);
  43. Assert.That(angle, Is.LessThan(5.0f), "Agent Velocity is not aligned with the off-mesh link.");
  44. }
  45. [UnityTearDown]
  46. public IEnumerator UnityTearDown()
  47. {
  48. yield return SceneManager.UnloadSceneAsync(k_SceneName);
  49. }
  50. }
  51. }