Newer
Older
DungeonShooting / DungeonShooting_Godot / src / test / TestNavigationPolygon.cs
@小李xl 小李xl on 24 Nov 2022 1 KB 生成NavigationPolygon功能完成
  1. using Godot;
  2.  
  3. /// <summary>
  4. /// 测试动态创建 NavigationPolygon
  5. /// </summary>
  6. public class TestNavigationPolygon : Navigation2D
  7. {
  8. public override void _Ready()
  9. {
  10. var nv = GetNode<NavigationPolygonInstance>("NavigationPolygonInstance");
  11.  
  12. var navpoy = nv.Navpoly;
  13. var outlines = navpoy.Outlines;
  14. var polygons = navpoy.Polygons;
  15. var vertices = navpoy.Vertices;
  16.  
  17. var polygon = new NavigationPolygon();
  18. // polygon.Vertices = new Vector2[]
  19. // {
  20. // new Vector2(0,0), new Vector2(200,200), new Vector2(200, 0), new Vector2(0, 200),
  21. // new Vector2(50,50), new Vector2(150,150), new Vector2(150, 50), new Vector2(50, 150)
  22. // };
  23. // polygon.AddPolygon(new int[] { 0, 2, 1, 3 });
  24. // polygon.AddPolygon(new int[] { 4, 6, 5, 7 });
  25.  
  26. polygon.AddOutline(new [] { new Vector2(0,0), new Vector2(200, 0), new Vector2(200,200), new Vector2(0, 200) });
  27. polygon.AddOutline(new [] { new Vector2(50,50), new Vector2(150, 50), new Vector2(150,150), new Vector2(50, 150) });
  28. polygon.MakePolygonsFromOutlines();
  29. nv.Navpoly = polygon;
  30. }
  31. }