NavMeshSurfaceAgentTests.cs 2.8 KB

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