Browse Source

Merge pull request #15489 from willnationsdev/gdnative-hook

Add EditorPlugin.build() build callbacks
Max Hilbrunner 7 năm trước cách đây
mục cha
commit
8a9e7ab6a6
5 tập tin đã thay đổi với 37 bổ sung4 xóa
  1. 12 0
      editor/editor_data.cpp
  2. 1 0
      editor/editor_data.h
  3. 13 4
      editor/editor_node.cpp
  4. 10 0
      editor/editor_plugin.cpp
  5. 1 0
      editor/editor_plugin.h

+ 12 - 0
editor/editor_data.cpp

@@ -420,6 +420,18 @@ void EditorData::paste_object_params(Object *p_object) {
 	}
 }
 
+bool EditorData::call_build() {
+
+	bool result = true;
+
+	for (int i = 0; i < editor_plugins.size() && result; i++) {
+
+		result &= editor_plugins[i]->build();
+	}
+
+	return result;
+}
+
 UndoRedo &EditorData::get_undo_redo() {
 
 	return undo_redo;

+ 1 - 0
editor/editor_data.h

@@ -197,6 +197,7 @@ public:
 	NodePath get_edited_scene_live_edit_root();
 	bool check_and_update_scene(int p_idx);
 	void move_edited_scene_to_index(int p_idx);
+	bool call_build();
 
 	void set_plugin_window_layout(Ref<ConfigFile> p_layout);
 	void get_plugin_window_layout(Ref<ConfigFile> p_layout);

+ 13 - 4
editor/editor_node.cpp

@@ -4271,12 +4271,21 @@ EditorBuildCallback EditorNode::build_callbacks[EditorNode::MAX_BUILD_CALLBACKS]
 
 bool EditorNode::call_build() {
 
-	for (int i = 0; i < build_callback_count; i++) {
-		if (!build_callbacks[i]())
-			return false;
+	bool builds_successful = true;
+
+	for (int i = 0; i < build_callback_count && builds_successful; i++) {
+		if (!build_callbacks[i]()) {
+			ERR_PRINT("A Godot Engine build callback failed.");
+			builds_successful = false;
+		}
 	}
 
-	return true;
+	if (builds_successful && !editor_data.call_build()) {
+		ERR_PRINT("An EditorPlugin build callback failed.");
+		builds_successful = false;
+	}
+
+	return builds_successful;
 }
 
 void EditorNode::_inherit_imported(const String &p_action) {

+ 10 - 0
editor/editor_plugin.cpp

@@ -689,6 +689,15 @@ void EditorPlugin::get_window_layout(Ref<ConfigFile> p_layout) {
 	}
 }
 
+bool EditorPlugin::build() {
+
+	if (get_script_instance() && get_script_instance()->has_method("build")) {
+		return get_script_instance()->call("build");
+	}
+
+	return true;
+}
+
 void EditorPlugin::queue_save_layout() const {
 
 	EditorNode::get_singleton()->save_layout();
@@ -767,6 +776,7 @@ void EditorPlugin::_bind_methods() {
 	ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::POOL_STRING_ARRAY, "get_breakpoints"));
 	ClassDB::add_virtual_method(get_class_static(), MethodInfo("set_window_layout", PropertyInfo(Variant::OBJECT, "layout", PROPERTY_HINT_RESOURCE_TYPE, "ConfigFile")));
 	ClassDB::add_virtual_method(get_class_static(), MethodInfo("get_window_layout", PropertyInfo(Variant::OBJECT, "layout", PROPERTY_HINT_RESOURCE_TYPE, "ConfigFile")));
+	ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "build"));
 
 	ADD_SIGNAL(MethodInfo("scene_changed", PropertyInfo(Variant::OBJECT, "scene_root", PROPERTY_HINT_RESOURCE_TYPE, "Node")));
 	ADD_SIGNAL(MethodInfo("scene_closed", PropertyInfo(Variant::STRING, "filepath")));

+ 1 - 0
editor/editor_plugin.h

@@ -192,6 +192,7 @@ public:
 	virtual void set_window_layout(Ref<ConfigFile> p_layout);
 	virtual void get_window_layout(Ref<ConfigFile> p_layout);
 	virtual void edited_scene_changed() {} // if changes are pending in editor, apply them
+	virtual bool build(); // builds with external tools. Returns true if safe to continue running scene.
 
 	EditorInterface *get_editor_interface();