Browse Source

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.
Thomas ten Cate 7 months ago
parent
commit
0c46089d1b
1 changed files with 10 additions and 2 deletions
  1. 10 2
      editor/editor_properties_array_dict.cpp

+ 10 - 2
editor/editor_properties_array_dict.cpp

@@ -33,6 +33,7 @@
 #include "core/input/input.h"
 #include "core/input/input.h"
 #include "core/io/marshalls.h"
 #include "core/io/marshalls.h"
 #include "editor/editor_file_system.h"
 #include "editor/editor_file_system.h"
+#include "editor/editor_node.h"
 #include "editor/editor_properties.h"
 #include "editor/editor_properties.h"
 #include "editor/editor_properties_vector.h"
 #include "editor/editor_properties_vector.h"
 #include "editor/editor_settings.h"
 #include "editor/editor_settings.h"
@@ -570,11 +571,18 @@ bool EditorPropertyArray::_is_drop_valid(const Dictionary &p_drag_data) const {
 		PackedStringArray files = drag_data["files"];
 		PackedStringArray files = drag_data["files"];
 
 
 		for (const String &file : files) {
 		for (const String &file : files) {
-			const String ftype = EditorFileSystem::get_singleton()->get_file_type(file);
+			int idx_in_dir;
+			EditorFileSystemDirectory const *dir = EditorFileSystem::get_singleton()->find_file(file, &idx_in_dir);
+			if (!dir) {
+				return false;
+			}
+			StringName ftype = dir->get_file_type(idx_in_dir);
+			String script_class = dir->get_file_resource_script_class(idx_in_dir);
+
 			for (String at : allowed_type.split(",")) {
 			for (String at : allowed_type.split(",")) {
 				at = at.strip_edges();
 				at = at.strip_edges();
 				// Fail if one of the files is not of allowed type.
 				// Fail if one of the files is not of allowed type.
-				if (!ClassDB::is_parent_class(ftype, at)) {
+				if (!ClassDB::is_parent_class(ftype, at) && !EditorNode::get_editor_data().script_class_is_parent(script_class, at)) {
 					return false;
 					return false;
 				}
 				}
 			}
 			}