summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorWindy Darian <p123456638@msn.com>2019-01-29 23:07:56 -0500
committerWindy Darian <p123456638@msn.com>2019-01-29 23:25:57 -0500
commitc478f3032112157865815c5ad892427b8d0fb531 (patch)
tree833df5c41bfd25746df9e888b8f65c9dc8a0263d /editor
parent35bb52011a4cbcd8ca3779ab1761244f06a33127 (diff)
Support script global class (class_name) when importing a scene
We could already choose a script global class for root_type at scene import config. However, it would fall back to default Spatial if a script global class is chosen. This will make sure the base type for the script class is used, and the script to root node is attached upon import.
Diffstat (limited to 'editor')
-rw-r--r--editor/import/resource_importer_scene.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp
index f230fa1b8b..cc852e75cb 100644
--- a/editor/import/resource_importer_scene.cpp
+++ b/editor/import/resource_importer_scene.cpp
@@ -1239,6 +1239,13 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p
}
String root_type = p_options["nodes/root_type"];
+ root_type = root_type.split(" ")[0]; // full root_type is "ClassName (filename.gd)" for a script global class.
+
+ Ref<Script> root_script = NULL;
+ if (ScriptServer::is_global_class(root_type)) {
+ root_script = ResourceLoader::load(ScriptServer::get_global_class_path(root_type));
+ root_type = ScriptServer::get_global_class_base(root_type);
+ }
if (scene->get_class() != root_type) {
Node *base_node = Object::cast_to<Node>(ClassDB::instance(root_type));
@@ -1251,6 +1258,10 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p
}
}
+ if (root_script.is_valid()) {
+ scene->set_script(Variant(root_script));
+ }
+
if (Object::cast_to<Spatial>(scene)) {
float root_scale = p_options["nodes/root_scale"];
Object::cast_to<Spatial>(scene)->scale(Vector3(root_scale, root_scale, root_scale));