Example #1
0
Object *CreateDialog::instance_selected() {

	TreeItem *selected = search_options->get_selected();

	if (selected) {

		Variant md = selected->get_metadata(0);

		String custom;
		if (md.get_type() != Variant::NIL)
			custom = md;

		if (custom != String()) {

			if (ScriptServer::is_global_class(custom)) {
				RES script = ResourceLoader::load(ScriptServer::get_global_class_path(custom));
				ERR_FAIL_COND_V(!script.is_valid(), NULL);

				Object *obj = ClassDB::instance(ScriptServer::get_global_class_base(custom));
				ERR_FAIL_COND_V(!obj, NULL);

				obj->set_script(script.get_ref_ptr());
				return obj;
			}
			return EditorNode::get_editor_data().instance_custom_type(selected->get_text(0), custom);
		} else {
			return ClassDB::instance(selected->get_text(0));
		}
	}

	return NULL;
}
Example #2
0
Object *EditorData::script_class_instance(const String &p_class) {
	if (ScriptServer::is_global_class(p_class)) {
		Object *obj = ClassDB::instance(ScriptServer::get_global_class_base(p_class));
		if (obj) {
			RES script = ResourceLoader::load(ScriptServer::get_global_class_path(p_class));
			if (script.is_valid())
				obj->set_script(script.get_ref_ptr());
			return obj;
		}
	}
	return NULL;
}