浏览代码

Document sub plugins

HolonProduction 11 月之前
父节点
当前提交
06d9bcd36e

二进制
tutorials/plugins/editor/img/sub_plugin_creation.webp


二进制
tutorials/plugins/editor/img/sub_plugin_moved.webp


+ 52 - 17
tutorials/plugins/editor/making_plugins.rst

@@ -282,7 +282,7 @@ click the button, you can see some text in the console:
 .. image:: img/making_plugins-custom_node_console.webp
 .. image:: img/making_plugins-custom_node_console.webp
 
 
 A custom dock
 A custom dock
-^^^^^^^^^^^^^
+~~~~~~~~~~~~~
 
 
 Sometimes, you need to extend the editor and add tools that are always available.
 Sometimes, you need to extend the editor and add tools that are always available.
 An easy way to do it is to add a new dock with a plugin. Docks are just scenes
 An easy way to do it is to add a new dock with a plugin. Docks are just scenes
@@ -413,18 +413,6 @@ the settings window. You should now have a custom dock:
 
 
 .. image:: img/making_plugins-custom_dock.webp
 .. image:: img/making_plugins-custom_dock.webp
 
 
-Going beyond
-~~~~~~~~~~~~
-
-Now that you've learned how to make basic plugins, you can extend the editor in
-several ways. Lots of functionality can be added to the editor with GDScript;
-it is a powerful way to create specialized editors without having to delve into
-C++ modules.
-
-You can make your own plugins to help yourself and share them in the
-`Asset Library <https://godotengine.org/asset-library/>`_ so that people
-can benefit from your work.
-
 .. _doc_making_plugins_autoload:
 .. _doc_making_plugins_autoload:
 
 
 Registering autoloads/singletons in plugins
 Registering autoloads/singletons in plugins
@@ -450,12 +438,12 @@ Use the following code to register a singleton from an editor plugin:
     const AUTOLOAD_NAME = "SomeAutoload"
     const AUTOLOAD_NAME = "SomeAutoload"
 
 
 
 
-    func _enter_tree():
+    func _enable_plugin():
         # The autoload can be a scene or script file.
         # The autoload can be a scene or script file.
         add_autoload_singleton(AUTOLOAD_NAME, "res://addons/my_addon/some_autoload.tscn")
         add_autoload_singleton(AUTOLOAD_NAME, "res://addons/my_addon/some_autoload.tscn")
 
 
 
 
-    func _exit_tree():
+    func _disable_plugin():
         remove_autoload_singleton(AUTOLOAD_NAME)
         remove_autoload_singleton(AUTOLOAD_NAME)
 
 
  .. code-tab:: csharp
  .. code-tab:: csharp
@@ -469,15 +457,62 @@ Use the following code to register a singleton from an editor plugin:
         // Replace this value with a PascalCase autoload name.
         // Replace this value with a PascalCase autoload name.
         private const string AutoloadName = "SomeAutoload";
         private const string AutoloadName = "SomeAutoload";
 
 
-        public override void _EnterTree()
+        public override void _EnablePlugin()
         {
         {
             // The autoload can be a scene or script file.
             // The autoload can be a scene or script file.
             AddAutoloadSingleton(AutoloadName, "res://addons/MyAddon/SomeAutoload.tscn");
             AddAutoloadSingleton(AutoloadName, "res://addons/MyAddon/SomeAutoload.tscn");
         }
         }
 
 
-        public override void _ExitTree()
+        public override void _DisablePlugin()
         {
         {
             RemoveAutoloadSingleton(AutoloadName);
             RemoveAutoloadSingleton(AutoloadName);
         }
         }
     }
     }
     #endif
     #endif
+
+Using sub-plugins
+~~~~~~~~~~~~~~~~~
+
+Often a plugin adds multiple things, for example a custom node and a panel.
+In those cases it might be easier to have a separate plugin script for each of those features.
+Sub-plugins can be used for this.
+
+First create all plugins and sub plugins as normal plugins:
+
+.. image:: img/sub_plugin_creation.webp
+
+Then move the sub plugins into the main plugin folder:
+
+.. image:: img/sub_plugin_moved.webp
+
+Godot will hide sub-plugins from the plugin list, so that a user can't enable or disable them.
+Instead the main plugin script should enable and disable sub-plugins like this:
+
+.. tabs::
+ .. code-tab:: gdscript GDScript
+
+    @tool
+    extends EditorPlugin
+
+    # The main plugin is located at res://addons/my_plugin/
+    const PLUGIN_NAME = "my_plugin"
+
+    func _enable_plugin():
+        EditorInterface.set_plugin_enabled(PLUGIN_NAME + "/node", true)
+        EditorInterface.set_plugin_enabled(PLUGIN_NAME + "/panel", true)
+
+    func _disable_plugin():
+        EditorInterface.set_plugin_enabled(PLUGIN_NAME + "/node", false)
+        EditorInterface.set_plugin_enabled(PLUGIN_NAME + "/panel", false)
+
+Going beyond
+~~~~~~~~~~~~
+
+Now that you've learned how to make basic plugins, you can extend the editor in
+several ways. Lots of functionality can be added to the editor with GDScript;
+it is a powerful way to create specialized editors without having to delve into
+C++ modules.
+
+You can make your own plugins to help yourself and share them in the
+`Asset Library <https://godotengine.org/asset-library/>`_ so that people
+can benefit from your work.