From 1537e66c8c0f01d9e91ee7285be3eed19c35ec19 Mon Sep 17 00:00:00 2001 From: Austen McRae Date: Tue, 3 Mar 2020 13:17:39 -0800 Subject: [PATCH] Expand Inspector Plugin tutorial (#3024) As a first-time creator of the inspector plugin, it took a while to actually understand exactly what's happening and what's needed, so I've expanded with the information that I felt would help make the tutorial easier for people doing their first foray into making one of these plugins. --- .../plugins/editor/inspector_plugins.rst | 41 ++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/tutorials/plugins/editor/inspector_plugins.rst b/tutorials/plugins/editor/inspector_plugins.rst index 5744a76d8..fe5e536e8 100644 --- a/tutorials/plugins/editor/inspector_plugins.rst +++ b/tutorials/plugins/editor/inspector_plugins.rst @@ -8,17 +8,46 @@ editing properties. This tutorial explains how to use the :ref:`class_EditorInspectorPlugin` and :ref:`class_EditorProperty` classes to write such plugins with the example of creating a custom value editor. -.. note:: +Setup +----- - To register these scripts as a new editor plugin, you have to create a - ``plugin.cfg`` file as described in :ref:`doc_making_plugins`. +Just like :ref:`doc_making_plugins`, we start out by making a new plugin, +getting a ``plugin.cfg`` file created, and start with our +:ref:`class_EditorPlugin`. However, instead of using +``add_custom_node`` or ``add_control_to_dock`` we'll use +``add_inspector_plugin``. + +.. tabs:: + .. code-tab:: gdscript GDScript + # MyEditorPlugin.gd + + tool extends EditorPlugin + + var plugin: EditorInspectorPlugin + + func _enter_tree(): + # EditorInspectorPlugin is a resource, so we use `new()` instead of `instance()`. + plugin = preload("res://addons/MyPlugin/MyInspectorPlugin.gd").new() + add_inspector_plugin(plugin) + + func _exit_tree(): + remove_inspector_plugin(plugin) EditorInspectorPlugin --------------------- -We start by creating a script extending the :ref:`class_EditorInspectorPlugin` -class. This is needed to initialize the plugin and add the custom property -editor that we'll later define. +To actually connect into the Inspector, we create a +:ref:`class_EditorInspectorPlugin` class. This script provides the "hooks" to +the inspector. Thanks to this class, the editor will call the functions within +the EditorInspectorPlugin while it goes through the process of building the UI +for the inspector. The script is used to check if we should enable ourselves for +any :ref:`class_Object` that is currently in the inspector (including any +:ref:`class_Resource` that is embedded!). + +Once enabled, EditorInspectorPlugin has methods that allow for adding +:ref:`class_EditorProperty` nodes or just custom :ref:`class_Control` nodes to +the beginning and end of the inspector for that :ref:`class_Object`, or for +overriding or changing existing property editors. .. tabs:: .. code-tab:: gdscript GDScript