NavMeshSurfaceModifierVolumeTests.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 NavMeshSurfaceModifierVolumeTests
  9. {
  10. NavMeshSurface surface;
  11. NavMeshModifierVolume modifier;
  12. [SetUp]
  13. public void CreatePlaneAndModifierVolume()
  14. {
  15. var go = GameObject.CreatePrimitive(PrimitiveType.Plane);
  16. surface = go.AddComponent<NavMeshSurface>();
  17. modifier = new GameObject().AddComponent<NavMeshModifierVolume>();
  18. }
  19. [TearDown]
  20. public void DestroyPlaneAndModifierVolume()
  21. {
  22. GameObject.DestroyImmediate(surface.gameObject);
  23. GameObject.DestroyImmediate(modifier.gameObject);
  24. }
  25. [Test]
  26. public void AreaAffectsNavMeshOverlapping()
  27. {
  28. modifier.center = Vector3.zero;
  29. modifier.size = Vector3.one;
  30. modifier.area = 4;
  31. surface.BuildNavMesh();
  32. var expectedAreaMask = 1 << 4;
  33. Assert.IsTrue(NavMeshSurfaceTests.HasNavMeshAtOrigin(expectedAreaMask));
  34. }
  35. [Test]
  36. public void AreaDoesNotAffectsNavMeshWhenNotOverlapping()
  37. {
  38. modifier.center = 1.1f * Vector3.right;
  39. modifier.size = Vector3.one;
  40. modifier.area = 4;
  41. surface.BuildNavMesh();
  42. var expectedAreaMask = 1;
  43. Assert.IsTrue(NavMeshSurfaceTests.HasNavMeshAtOrigin(expectedAreaMask));
  44. }
  45. [Test]
  46. public void BuildUsesOnlyIncludedModifierVolume()
  47. {
  48. modifier.center = Vector3.zero;
  49. modifier.size = Vector3.one;
  50. modifier.area = 4;
  51. modifier.gameObject.layer = 7;
  52. surface.layerMask = ~(1 << 7);
  53. surface.BuildNavMesh();
  54. var expectedAreaMask = 1;
  55. Assert.IsTrue(NavMeshSurfaceTests.HasNavMeshAtOrigin(expectedAreaMask));
  56. }
  57. }
  58. #endif