Merge pull request #58170 from timothyqiu/gridmap-used-id
Add `GridMap.get_used_cells_by_item`
This commit is contained in:
commit
5cbd982df1
|
@ -79,6 +79,13 @@
|
|||
Returns an array of [Vector3] with the non-empty cell coordinates in the grid map.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_used_cells_by_item" qualifiers="const">
|
||||
<return type="Array" />
|
||||
<argument index="0" name="item" type="int" />
|
||||
<description>
|
||||
Returns an array of all cells with the given item index specified in [code]item[/code].
|
||||
</description>
|
||||
</method>
|
||||
<method name="make_baked_meshes">
|
||||
<return type="void" />
|
||||
<argument index="0" name="gen_lightmap_uv" type="bool" default="false" />
|
||||
|
|
|
@ -878,6 +878,7 @@ void GridMap::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("clear"), &GridMap::clear);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_used_cells"), &GridMap::get_used_cells);
|
||||
ClassDB::bind_method(D_METHOD("get_used_cells_by_item", "item"), &GridMap::get_used_cells_by_item);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_meshes"), &GridMap::get_meshes);
|
||||
ClassDB::bind_method(D_METHOD("get_bake_meshes"), &GridMap::get_bake_meshes);
|
||||
|
@ -950,6 +951,18 @@ Array GridMap::get_used_cells() const {
|
|||
return a;
|
||||
}
|
||||
|
||||
Array GridMap::get_used_cells_by_item(int p_item) const {
|
||||
Array a;
|
||||
for (const KeyValue<IndexKey, Cell> &E : cell_map) {
|
||||
if (E.value.item == p_item) {
|
||||
Vector3 p(E.key.x, E.key.y, E.key.z);
|
||||
a.push_back(p);
|
||||
}
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
Array GridMap::get_meshes() const {
|
||||
if (mesh_library.is_null()) {
|
||||
return Array();
|
||||
|
|
|
@ -266,6 +266,7 @@ public:
|
|||
float get_cell_scale() const;
|
||||
|
||||
Array get_used_cells() const;
|
||||
Array get_used_cells_by_item(int p_item) const;
|
||||
|
||||
Array get_meshes() const;
|
||||
|
||||
|
|
Loading…
Reference in New Issue