diff --git a/tutorials/plugins/editor/making_plugins.rst b/tutorials/plugins/editor/making_plugins.rst index 801ca6d40..b22e9aa81 100644 --- a/tutorials/plugins/editor/making_plugins.rst +++ b/tutorials/plugins/editor/making_plugins.rst @@ -36,8 +36,11 @@ You should end up with a directory structure like this: Now, open the script editor, click the **File** menu, choose **New TextFile**, then navigate to the plugin folder and name the file ``plugin.cfg``. -Add the following structure to ``plugin.cfg``:: +Add the following structure to ``plugin.cfg``: +.. tabs:: + .. code-tab:: gdscript GDScript + [plugin] name="My Custom Node" @@ -46,6 +49,16 @@ Add the following structure to ``plugin.cfg``:: version="1.0.0" script="custom_node.gd" + .. code-tab:: csharp + + [plugin] + + name="My Custom Node" + description="A custom node made to extend the Godot Engine." + author="Your Name Here" + version="1.0.0" + script="CustomNode.cs" + This is a simple INI file with metadata about your plugin. You need to set the name and description so people can understand what it does. Don't forget to add your own name so you can be properly credited. Add a version number @@ -69,8 +82,9 @@ default GDScript template from your file and replace it with the following structure: .. _doc_making_plugins_template_code: -.. code-block:: python - +.. tabs:: + .. code-tab:: gdscript GDScript + tool extends EditorPlugin @@ -82,6 +96,27 @@ structure: # Clean-up of the plugin goes here pass + .. code-tab:: csharp + + #if TOOLS + using Godot; + using System; + + [Tool] + public class CustomNode : EditorPlugin + { + public override void _EnterTree() + { + // Initialization of the plugin goes here + } + + public override void _ExitTree() + { + // Initialization of the plugin goes here + } + } + #endif + This is a good template to use when creating new plugins. A custom node @@ -103,8 +138,11 @@ the ``tool`` keyword, it can be added so the script runs in the editor. For this tutorial, we'll create a simple button that prints a message when clicked. For that, we'll need a simple script that extends from :ref:`class_Button`. It could also extend -:ref:`class_BaseButton` if you prefer:: +:ref:`class_BaseButton` if you prefer: +.. tabs:: + .. code-tab:: gdscript GDScript + tool extends Button @@ -114,7 +152,26 @@ clicked. For that, we'll need a simple script that extends from func clicked(): print("You clicked me!") -That's it for our basic button. You can save this as ``button.gd`` inside the + .. code-tab:: csharp + + using Godot; + using System; + + [Tool] + public class MyButton : Button + { + public override void _EnterTree() + { + Connect("pressed", this, "clicked"); + } + + public void clicked() + { + GD.Print("You clicked me!"); + } + } + +That's it for our basic button. You can save this as ``my_button.gd`` inside the plugin folder. You'll also need a 16×16 icon to show in the scene tree. If you don't have one, you can grab the default one from the engine and save it in your `addons/my_custom_node` folder as `icon.png`, or use the default Godot logo @@ -123,21 +180,51 @@ don't have one, you can grab the default one from the engine and save it in your .. image:: img/making_plugins-custom_node_icon.png Now, we need to add it as a custom type so it shows on the **Create New Node** -dialog. For that, change the ``custom_node.gd`` script to the following:: +dialog. For that, change the ``custom_node.gd`` script to the following: +.. tabs:: + .. code-tab:: gdscript GDScript + tool extends EditorPlugin func _enter_tree(): # Initialization of the plugin goes here # Add the new type with a name, a parent type, a script and an icon - add_custom_type("MyButton", "Button", preload("button.gd"), preload("icon.png")) + add_custom_type("MyButton", "Button", preload("my_button.gd"), preload("icon.png")) func _exit_tree(): # Clean-up of the plugin goes here # Always remember to remove it from the engine when deactivated remove_custom_type("MyButton") + .. code-tab:: csharp + + #if TOOLS + using Godot; + using System; + + [Tool] + public class CustomNode : EditorPlugin + { + public override void _EnterTree() + { + // Initialization of the plugin goes here + // Add the new type with a name, a parent type, a script and an icon + var script = GD.Load