Skip to content

Commit b1eb019

Browse files
committed
Allow dragging custom resources onto array property editor
This duplicates some of the logic in EditorResourcePicker, but that's unavoidable: EditorResourcePicker works on a single, loaded resource, whereas we'd like this to be efficient and not need to load all (potentially many) dragged resources. Instead, we use the EditorFileSystem cache to get the information we need. Note that EditorResourcePicker also supports some automatic conversions, such as from Shader to ShaderMaterial. This change does not attempt to make that work for arrays as well.
1 parent 8dc3067 commit b1eb019

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

editor/editor_properties_array_dict.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "core/input/input.h"
3434
#include "core/io/marshalls.h"
3535
#include "editor/editor_file_system.h"
36+
#include "editor/editor_node.h"
3637
#include "editor/editor_properties.h"
3738
#include "editor/editor_properties_vector.h"
3839
#include "editor/editor_settings.h"
@@ -572,12 +573,18 @@ bool EditorPropertyArray::_is_drop_valid(const Dictionary &p_drag_data) const {
572573

573574
for (int i = 0; i < files.size(); i++) {
574575
const String &file = files[i];
575-
String ftype = EditorFileSystem::get_singleton()->get_file_type(file);
576+
int idx_in_dir;
577+
EditorFileSystemDirectory const *dir = EditorFileSystem::get_singleton()->find_file(file, &idx_in_dir);
578+
if (!dir) {
579+
return false;
580+
}
581+
StringName ftype = dir->get_file_type(idx_in_dir);
582+
String script_class = dir->get_file_resource_script_class(idx_in_dir);
576583

577584
for (int j = 0; j < allowed_type.get_slice_count(","); j++) {
578585
String at = allowed_type.get_slice(",", j).strip_edges();
579586
// Fail if one of the files is not of allowed type.
580-
if (!ClassDB::is_parent_class(ftype, at)) {
587+
if (!ClassDB::is_parent_class(ftype, at) && !EditorNode::get_editor_data().script_class_is_parent(script_class, at)) {
581588
return false;
582589
}
583590
}

0 commit comments

Comments
 (0)