Newer
Older
DungeonShooting / DungeonShooting_Godot / src / test / TestNavigation.cs
  1. using Godot;
  2.  
  3. /// <summary>
  4. /// 该demo是以3.4为基础做的导航demo, 后面3.5出了新的导航系统, 游戏中已采用新的导航方案
  5. /// </summary>
  6. public class TestNavigation : Node2D
  7. {
  8.  
  9. private Navigation2D Navigation2D;
  10. private Vector2[] points = new Vector2[0];
  11.  
  12. public override void _Ready()
  13. {
  14. Navigation2D = GetNode<Navigation2D>("Position2D/Navigation2D");
  15. }
  16.  
  17. public override void _Input(InputEvent @event)
  18. {
  19. if (@event is InputEventMouseButton ieb) {
  20. if (ieb.ButtonIndex == (int)ButtonList.Left && ieb.Pressed)
  21. {
  22. points = Navigation2D.GetSimplePath(Vector2.Zero, Navigation2D.ToLocal(ieb.Position));
  23. Update();
  24. string str = "";
  25. foreach (var item in points)
  26. {
  27. str += item;
  28. }
  29. GD.Print("路径: " + points.Length + ", " + str);
  30. }
  31. }
  32. }
  33.  
  34. public override void _Draw()
  35. {
  36. if (points.Length >= 2)
  37. {
  38. GD.Print("绘制线段...");
  39. DrawPolyline(points, Colors.Red);
  40. // DrawMultiline(points, Colors.Red);
  41. }
  42. }
  43. }