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.

NavMeshSurfaceAgentTests.cs 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #if UNITY_EDITOR || UNITY_STANDALONE
  2. using System.Collections;
  3. using NUnit.Framework;
  4. using UnityEngine;
  5. using UnityEngine.AI;
  6. using UnityEngine.TestTools;
  7. namespace Unity.AI.Navigation.Tests
  8. {
  9. class NavMeshSurfaceAgentTests
  10. {
  11. NavMeshSurface m_Surface;
  12. NavMeshAgent m_Agent;
  13. [SetUp]
  14. public void Setup()
  15. {
  16. m_Surface = GameObject.CreatePrimitive(PrimitiveType.Plane).AddComponent<NavMeshSurface>();
  17. }
  18. [TearDown]
  19. public void TearDown()
  20. {
  21. Object.DestroyImmediate(m_Agent.gameObject);
  22. Object.DestroyImmediate(m_Surface.gameObject);
  23. m_Agent = null;
  24. m_Surface = null;
  25. }
  26. [Test]
  27. public void AgentIdentifiesSurfaceOwner()
  28. {
  29. m_Surface.BuildNavMesh();
  30. m_Agent = new GameObject("Agent").AddComponent<NavMeshAgent>();
  31. Assert.AreEqual(m_Surface, m_Agent.navMeshOwner);
  32. Assert.IsTrue(m_Agent.isOnNavMesh);
  33. }
  34. [Test]
  35. [Ignore("1012991 : Missing functionality for notifying the NavMeshAgent about the removal of the NavMesh.")]
  36. public void AgentDetachesAndAttachesToSurface()
  37. {
  38. m_Surface.BuildNavMesh();
  39. m_Agent = new GameObject("Agent").AddComponent<NavMeshAgent>();
  40. Assert.AreEqual(m_Surface, m_Agent.navMeshOwner);
  41. Assert.IsTrue(m_Agent.isOnNavMesh);
  42. m_Surface.enabled = false;
  43. Assert.IsNull(m_Agent.navMeshOwner);
  44. Assert.IsFalse(m_Agent.isOnNavMesh);
  45. m_Surface.enabled = true;
  46. Assert.AreEqual(m_Surface, m_Agent.navMeshOwner);
  47. Assert.IsTrue(m_Agent.isOnNavMesh);
  48. }
  49. /*
  50. [Test]
  51. public void AgentIsOnNavMeshWhenMatchingAgentTypeID()
  52. {
  53. m_Surface.agentTypeID = 1234;
  54. m_Surface.BuildNavMesh();
  55. m_Agent = new GameObject("Agent").AddComponent<NavMeshAgent>();
  56. Assert.IsFalse(m_Agent.isOnNavMesh);
  57. m_Agent.agentTypeID = 1234;
  58. Assert.IsTrue(m_Agent.isOnNavMesh);
  59. }
  60. */
  61. [UnityTest]
  62. public IEnumerator AgentAlignsToSurfaceNextFrame()
  63. {
  64. m_Surface.transform.rotation = new Quaternion(-0.679622f, 0.351242f, -0.373845f, 0.524388f);
  65. m_Surface.BuildNavMesh();
  66. m_Agent = new GameObject("Agent").AddComponent<NavMeshAgent>();
  67. yield return null;
  68. var residual = m_Surface.transform.up - m_Agent.transform.up;
  69. Assert.IsTrue(residual.magnitude < 0.01f);
  70. }
  71. [UnityTest]
  72. public IEnumerator AgentDoesNotAlignToSurfaceNextFrame()
  73. {
  74. m_Surface.transform.rotation = new Quaternion(-0.679622f, 0.351242f, -0.373845f, 0.524388f);
  75. m_Surface.BuildNavMesh();
  76. m_Agent = new GameObject("Agent").AddComponent<NavMeshAgent>();
  77. m_Agent.updateUpAxis = false;
  78. yield return null;
  79. var residual = Vector3.up - m_Agent.transform.up;
  80. Assert.IsTrue(residual.magnitude < 0.01f);
  81. }
  82. }
  83. }
  84. #endif