Просмотр исходного кода

Merge pull request #60661 from smix8/navigation_region_rid_3.x

[3.x] Add get_region_rid() to NavigationPolygonInstance and NavigationMeshInstance
Rémi Verschelde 3 лет назад
Родитель
Сommit
973bbb5c0e

+ 6 - 0
doc/classes/NavigationMeshInstance.xml

@@ -15,6 +15,12 @@
 				Bakes the [NavigationMesh]. The baking is done in a separate thread because navigation baking is not a cheap operation. This can be done at runtime. When it is completed, it automatically sets the new [NavigationMesh].
 			</description>
 		</method>
+		<method name="get_region_rid" qualifiers="const">
+			<return type="RID" />
+			<description>
+				Returns the [RID] of this region on the [NavigationServer]. Combined with [method NavigationServer.map_get_closest_point_owner] can be used to identify the [NavigationMeshInstance] closest to a point on the merged navigation map.
+			</description>
+		</method>
 	</methods>
 	<members>
 		<member name="enabled" type="bool" setter="set_enabled" getter="is_enabled" default="true">

+ 6 - 0
doc/classes/NavigationPolygonInstance.xml

@@ -7,6 +7,12 @@
 	<tutorials>
 	</tutorials>
 	<methods>
+		<method name="get_region_rid" qualifiers="const">
+			<return type="RID" />
+			<description>
+				Returns the [RID] of this region on the [Navigation2DServer]. Combined with [method Navigation2DServer.map_get_closest_point_owner] can be used to identify the [NavigationPolygonInstance] closest to a point on the merged navigation map.
+			</description>
+		</method>
 	</methods>
 	<members>
 		<member name="enabled" type="bool" setter="set_enabled" getter="is_enabled" default="true">

+ 6 - 0
scene/2d/navigation_polygon.cpp

@@ -381,6 +381,10 @@ bool NavigationPolygonInstance::is_enabled() const {
 	return enabled;
 }
 
+RID NavigationPolygonInstance::get_region_rid() const {
+	return region;
+}
+
 /////////////////////////////
 #ifdef TOOLS_ENABLED
 Rect2 NavigationPolygonInstance::_edit_get_rect() const {
@@ -532,6 +536,8 @@ void NavigationPolygonInstance::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &NavigationPolygonInstance::set_enabled);
 	ClassDB::bind_method(D_METHOD("is_enabled"), &NavigationPolygonInstance::is_enabled);
 
+	ClassDB::bind_method(D_METHOD("get_region_rid"), &NavigationPolygonInstance::get_region_rid);
+
 	ClassDB::bind_method(D_METHOD("_navpoly_changed"), &NavigationPolygonInstance::_navpoly_changed);
 
 	ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "navpoly", PROPERTY_HINT_RESOURCE_TYPE, "NavigationPolygon"), "set_navigation_polygon", "get_navigation_polygon");

+ 2 - 0
scene/2d/navigation_polygon.h

@@ -116,6 +116,8 @@ public:
 	void set_enabled(bool p_enabled);
 	bool is_enabled() const;
 
+	RID get_region_rid() const;
+
 	void set_navigation_polygon(const Ref<NavigationPolygon> &p_navpoly);
 	Ref<NavigationPolygon> get_navigation_polygon() const;
 

+ 6 - 0
scene/3d/navigation_mesh_instance.cpp

@@ -69,6 +69,10 @@ bool NavigationMeshInstance::is_enabled() const {
 	return enabled;
 }
 
+RID NavigationMeshInstance::get_region_rid() const {
+	return region;
+}
+
 /////////////////////////////
 
 void NavigationMeshInstance::_notification(int p_what) {
@@ -210,6 +214,8 @@ void NavigationMeshInstance::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &NavigationMeshInstance::set_enabled);
 	ClassDB::bind_method(D_METHOD("is_enabled"), &NavigationMeshInstance::is_enabled);
 
+	ClassDB::bind_method(D_METHOD("get_region_rid"), &NavigationMeshInstance::get_region_rid);
+
 	ClassDB::bind_method(D_METHOD("bake_navigation_mesh"), &NavigationMeshInstance::bake_navigation_mesh);
 	ClassDB::bind_method(D_METHOD("_bake_finished", "nav_mesh"), &NavigationMeshInstance::_bake_finished);
 

+ 2 - 0
scene/3d/navigation_mesh_instance.h

@@ -57,6 +57,8 @@ public:
 	void set_enabled(bool p_enabled);
 	bool is_enabled() const;
 
+	RID get_region_rid() const;
+
 	void set_navigation_mesh(const Ref<NavigationMesh> &p_navmesh);
 	Ref<NavigationMesh> get_navigation_mesh() const;