NavMeshSurfaceModifierTests.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. [TestFixture]
  8. public class NavMeshSurfaceModifierTests
  9. {
  10. NavMeshSurface surface;
  11. NavMeshModifier modifier;
  12. [SetUp]
  13. public void CreatePlaneWithModifier()
  14. {
  15. var plane = GameObject.CreatePrimitive(PrimitiveType.Plane);
  16. surface = plane.AddComponent<NavMeshSurface>();
  17. modifier = plane.AddComponent<NavMeshModifier>();
  18. }
  19. [TearDown]
  20. public void DestroyPlaneWithModifier()
  21. {
  22. GameObject.DestroyImmediate(modifier.gameObject);
  23. }
  24. [Test]
  25. public void ModifierIgnoreAffectsSelf()
  26. {
  27. modifier.ignoreFromBuild = true;
  28. surface.BuildNavMesh();
  29. Assert.IsFalse(NavMeshSurfaceTests.HasNavMeshAtOrigin());
  30. }
  31. [Test]
  32. public void ModifierIgnoreAffectsChild()
  33. {
  34. modifier.ignoreFromBuild = true;
  35. modifier.GetComponent<MeshRenderer>().enabled = false;
  36. var childPlane = GameObject.CreatePrimitive(PrimitiveType.Plane);
  37. childPlane.transform.SetParent(modifier.transform);
  38. surface.BuildNavMesh();
  39. Assert.IsFalse(NavMeshSurfaceTests.HasNavMeshAtOrigin());
  40. GameObject.DestroyImmediate(childPlane);
  41. }
  42. [Test]
  43. public void ModifierIgnoreDoesNotAffectSibling()
  44. {
  45. modifier.ignoreFromBuild = true;
  46. modifier.GetComponent<MeshRenderer>().enabled = false;
  47. var siblingPlane = GameObject.CreatePrimitive(PrimitiveType.Plane);
  48. surface.BuildNavMesh();
  49. Assert.IsTrue(NavMeshSurfaceTests.HasNavMeshAtOrigin());
  50. GameObject.DestroyImmediate(siblingPlane);
  51. }
  52. [Test]
  53. public void ModifierOverrideAreaAffectsSelf()
  54. {
  55. modifier.area = 4;
  56. modifier.overrideArea = true;
  57. surface.BuildNavMesh();
  58. var expectedAreaMask = 1 << 4;
  59. Assert.IsTrue(NavMeshSurfaceTests.HasNavMeshAtOrigin(expectedAreaMask));
  60. }
  61. [Test]
  62. public void ModifierOverrideAreaAffectsChild()
  63. {
  64. modifier.area = 4;
  65. modifier.overrideArea = true;
  66. modifier.GetComponent<MeshRenderer>().enabled = false;
  67. var childPlane = GameObject.CreatePrimitive(PrimitiveType.Plane);
  68. childPlane.transform.SetParent(modifier.transform);
  69. surface.BuildNavMesh();
  70. var expectedAreaMask = 1 << 4;
  71. Assert.IsTrue(NavMeshSurfaceTests.HasNavMeshAtOrigin(expectedAreaMask));
  72. GameObject.DestroyImmediate(childPlane);
  73. }
  74. [Test]
  75. public void ModifierOverrideAreaDoesNotAffectSibling()
  76. {
  77. modifier.area = 4;
  78. modifier.overrideArea = true;
  79. modifier.GetComponent<MeshRenderer>().enabled = false;
  80. var siblingPlane = GameObject.CreatePrimitive(PrimitiveType.Plane);
  81. surface.BuildNavMesh();
  82. var expectedAreaMask = 1;
  83. Assert.IsTrue(NavMeshSurfaceTests.HasNavMeshAtOrigin(expectedAreaMask));
  84. GameObject.DestroyImmediate(siblingPlane);
  85. }
  86. }
  87. #endif