navigation_region_2d.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /**************************************************************************/
  2. /* navigation_region_2d.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef NAVIGATION_REGION_2D_H
  31. #define NAVIGATION_REGION_2D_H
  32. #include "scene/resources/2d/navigation_polygon.h"
  33. class NavigationRegion2D : public Node2D {
  34. GDCLASS(NavigationRegion2D, Node2D);
  35. bool enabled = true;
  36. bool use_edge_connections = true;
  37. RID region;
  38. RID map_override;
  39. uint32_t navigation_layers = 1;
  40. real_t enter_cost = 0.0;
  41. real_t travel_cost = 1.0;
  42. Ref<NavigationPolygon> navigation_polygon;
  43. Transform2D current_global_transform;
  44. void _navigation_polygon_changed();
  45. #ifdef DEBUG_ENABLED
  46. private:
  47. RID debug_mesh_rid;
  48. RID debug_instance_rid;
  49. bool debug_mesh_dirty = true;
  50. void _free_debug();
  51. void _update_debug_mesh();
  52. void _update_debug_edge_connections_mesh();
  53. void _update_debug_baking_rect();
  54. void _navigation_map_changed(RID p_map);
  55. void _navigation_debug_changed();
  56. #endif // DEBUG_ENABLED
  57. protected:
  58. void _notification(int p_what);
  59. static void _bind_methods();
  60. #ifndef DISABLE_DEPRECATED
  61. bool _set(const StringName &p_name, const Variant &p_value);
  62. bool _get(const StringName &p_name, Variant &r_ret) const;
  63. #endif // DISABLE_DEPRECATED
  64. public:
  65. #ifdef DEBUG_ENABLED
  66. virtual Rect2 _edit_get_rect() const override;
  67. virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const override;
  68. #endif // DEBUG_ENABLED
  69. RID get_rid() const;
  70. void set_enabled(bool p_enabled);
  71. bool is_enabled() const;
  72. void set_navigation_map(RID p_navigation_map);
  73. RID get_navigation_map() const;
  74. void set_use_edge_connections(bool p_enabled);
  75. bool get_use_edge_connections() const;
  76. void set_navigation_layers(uint32_t p_navigation_layers);
  77. uint32_t get_navigation_layers() const;
  78. void set_navigation_layer_value(int p_layer_number, bool p_value);
  79. bool get_navigation_layer_value(int p_layer_number) const;
  80. RID get_region_rid() const;
  81. void set_enter_cost(real_t p_enter_cost);
  82. real_t get_enter_cost() const;
  83. void set_travel_cost(real_t p_travel_cost);
  84. real_t get_travel_cost() const;
  85. void set_navigation_polygon(const Ref<NavigationPolygon> &p_navigation_polygon);
  86. Ref<NavigationPolygon> get_navigation_polygon() const;
  87. PackedStringArray get_configuration_warnings() const override;
  88. void bake_navigation_polygon(bool p_on_thread);
  89. void _bake_finished(Ref<NavigationPolygon> p_navigation_polygon);
  90. bool is_baking() const;
  91. NavigationRegion2D();
  92. ~NavigationRegion2D();
  93. private:
  94. void _region_enter_navigation_map();
  95. void _region_exit_navigation_map();
  96. void _region_update_transform();
  97. };
  98. #endif // NAVIGATION_REGION_2D_H