mirror of
https://github.com/godotengine/godot-docs.git
synced 2026-01-03 05:48:42 +03:00
Adapt tutorial hyperlinks after godotengine/godot#24640
This commit is contained in:
@@ -65,10 +65,10 @@ when needed:
|
||||
|
||||
When this plugin is activated, it will create a new instance of the import
|
||||
plugin (which we'll soon make) and add it to the editor using the
|
||||
:ref:`add_import_plugin<class_EditorPlugin_add_import_plugin>` method. We store
|
||||
:ref:`add_import_plugin() <class_EditorPlugin_method_add_import_plugin>` method. We store
|
||||
a reference to it in a class member ``import_plugin`` so we can refer to it
|
||||
later when removing it. The
|
||||
:ref:`remove_import_plugin<class_EditorPlugin_remove_import_plugin>` method is
|
||||
:ref:`remove_import_plugin() <class_EditorPlugin_method_remove_import_plugin>` method is
|
||||
called when the plugin is deactivated to clean up the memory and let the editor
|
||||
know the import plugin isn't available anymore.
|
||||
|
||||
@@ -80,7 +80,7 @@ The EditorImportPlugin class
|
||||
----------------------------
|
||||
|
||||
The main character of the show is the
|
||||
:ref:`EditorImportPlugin class<class_EditorImportPlugin>`. It is responsible to
|
||||
:ref:`EditorImportPlugin class <class_EditorImportPlugin>`. It is responsible to
|
||||
implement the methods that are called by Godot when it needs to know how to deal
|
||||
with files.
|
||||
|
||||
@@ -96,7 +96,7 @@ Let's begin to code our plugin, one method at time:
|
||||
return "demos.sillymaterial"
|
||||
|
||||
The first method is the
|
||||
:ref:`get_importer_name<class_EditorImportPlugin_get_importer_name>`. This is a
|
||||
:ref:`get_importer_name()<class_EditorImportPlugin_method_get_importer_name>`. This is a
|
||||
unique name to your plugin that is used by Godot to know which import was used
|
||||
in a certain file. When the files needs to be reimported, the editor will know
|
||||
which plugin to call.
|
||||
@@ -106,7 +106,7 @@ which plugin to call.
|
||||
func get_visible_name():
|
||||
return "Silly Material"
|
||||
|
||||
The :ref:`get_visible_name<class_EditorImportPlugin_get_visible_name>` method is
|
||||
The :ref:`get_visible_name()<class_EditorImportPlugin_method_get_visible_name>` method is
|
||||
responsible to inform the name of the type it imports and will be shown to the
|
||||
user in the Import dock.
|
||||
|
||||
@@ -120,7 +120,7 @@ with a descriptive name for your plugin.
|
||||
return ["mtxt"]
|
||||
|
||||
Godot's import system detects file types by their extension. In the
|
||||
:ref:`get_recognized_extensions<class_EditorImportPlugin_get_recognized_extensions>`
|
||||
:ref:`get_recognized_extensions()<class_EditorImportPlugin_method_get_recognized_extensions>`
|
||||
method you return an array of strings to represent each extension that this
|
||||
plugin can understand. If an extension is recognized by more than one plugin,
|
||||
the user can select which one to use when importing the files.
|
||||
@@ -192,7 +192,7 @@ plugin:
|
||||
func get_preset_count():
|
||||
return Presets.size()
|
||||
|
||||
The :ref:`get_preset_count<class_EditorImportPlugin_get_preset_count>` method
|
||||
The :ref:`get_preset_count() <class_EditorImportPlugin_method_get_preset_count>` method
|
||||
returns the amount of presets that this plugins defines. We only have one preset
|
||||
now, but we can make this method future-proof by returning the size of our
|
||||
``Presets`` enumeration.
|
||||
@@ -208,7 +208,7 @@ now, but we can make this method future-proof by returning the size of our
|
||||
|
||||
|
||||
Here we have the
|
||||
:ref:`get_preset_name<class_EditorImportPlugin_get_preset_name>` method, which
|
||||
:ref:`get_preset_name() <class_EditorImportPlugin_method_get_preset_name>` method, which
|
||||
gives names to the presets as they will be presented to the user, so be sure to
|
||||
use short and clear names.
|
||||
|
||||
@@ -233,24 +233,24 @@ you do this you have to be careful when you add more presets.
|
||||
return []
|
||||
|
||||
This is the method which defines the available options.
|
||||
:ref:`get_import_options<class_EditorImportPlugin_get_import_options>` returns
|
||||
:ref:`get_import_options() <class_EditorImportPlugin_method_get_import_options>` returns
|
||||
an array of dictionaries, and each dictionary contains a few keys that are
|
||||
checked to customize the option as its shown to the user. The following table
|
||||
shows the possible keys:
|
||||
|
||||
+-------------------+------------+---------------------------------------------------------------------------------------------------------+
|
||||
| Key | Type | Description |
|
||||
+===================+============+=========================================================================================================+
|
||||
| ``name`` | String | The name of the option. When showed, underscores become spaces and first letters are capitalized. |
|
||||
+-------------------+------------+---------------------------------------------------------------------------------------------------------+
|
||||
| ``default_value`` | Any | The default value of the option for this preset. |
|
||||
+-------------------+------------+---------------------------------------------------------------------------------------------------------+
|
||||
| ``property_hint`` | Enum value | One of the :ref:`PropertyHint<enum_@GlobalScope_PropertyHint>` values to use as hint. |
|
||||
+-------------------+------------+---------------------------------------------------------------------------------------------------------+
|
||||
| ``hint_string`` | String | The hint text of the property. The same as you'd add in the ``export`` statement in GDScript. |
|
||||
+-------------------+------------+---------------------------------------------------------------------------------------------------------+
|
||||
| ``usage`` | Enum value | One of the :ref:`PropertyUsageFlags<enum_@GlobalScope_PropertyUsageFlags>` values to define the usage. |
|
||||
+-------------------+------------+---------------------------------------------------------------------------------------------------------+
|
||||
+-------------------+------------+----------------------------------------------------------------------------------------------------------+
|
||||
| Key | Type | Description |
|
||||
+===================+============+==========================================================================================================+
|
||||
| ``name`` | String | The name of the option. When showed, underscores become spaces and first letters are capitalized. |
|
||||
+-------------------+------------+----------------------------------------------------------------------------------------------------------+
|
||||
| ``default_value`` | Any | The default value of the option for this preset. |
|
||||
+-------------------+------------+----------------------------------------------------------------------------------------------------------+
|
||||
| ``property_hint`` | Enum value | One of the :ref:`PropertyHint <enum_@GlobalScope_PropertyHint>` values to use as hint. |
|
||||
+-------------------+------------+----------------------------------------------------------------------------------------------------------+
|
||||
| ``hint_string`` | String | The hint text of the property. The same as you'd add in the ``export`` statement in GDScript. |
|
||||
+-------------------+------------+----------------------------------------------------------------------------------------------------------+
|
||||
| ``usage`` | Enum value | One of the :ref:`PropertyUsageFlags <enum_@GlobalScope_PropertyUsageFlags>` values to define the usage. |
|
||||
+-------------------+------------+----------------------------------------------------------------------------------------------------------+
|
||||
|
||||
The ``name`` and ``default_value`` keys are **mandatory**, the rest are optional.
|
||||
|
||||
@@ -271,7 +271,7 @@ of options first and then change it based on the preset.
|
||||
return true
|
||||
|
||||
For the
|
||||
:ref:`get_option_visibility<class_EditorImportPlugin_get_option_visibility>`
|
||||
:ref:`get_option_visibility() <class_EditorImportPlugin_method_get_option_visibility>`
|
||||
method, we simply return ``true`` because all of our options (i.e. the single
|
||||
one we defined) are visible all the time.
|
||||
|
||||
@@ -282,7 +282,7 @@ The ``import`` method
|
||||
---------------------
|
||||
|
||||
The heavy part of the process, responsible for the converting the files into
|
||||
resources, is covered by the :ref:`import<class_EditorImportPlugin_import>`
|
||||
resources, is covered by the :ref:`import() <class_EditorImportPlugin_method_import>`
|
||||
method. Our sample code is a bit long, so let's split in a few parts:
|
||||
|
||||
::
|
||||
@@ -298,7 +298,7 @@ method. Our sample code is a bit long, so let's split in a few parts:
|
||||
file.close()
|
||||
|
||||
The first part of our import method opens and reads the source file. We use the
|
||||
:ref:`File<class_File>` class to do that, passing the ``source_file``
|
||||
:ref:`File <class_File>` class to do that, passing the ``source_file``
|
||||
parameter which is provided by the editor.
|
||||
|
||||
If there's an error when opening the file, we return it to let the editor know
|
||||
@@ -320,7 +320,7 @@ This code takes the line of the file it read before and splits it in pieces
|
||||
that are separated by a comma. If there are more or less than the three values,
|
||||
it considers the file invalid and reports an error.
|
||||
|
||||
Then it creates a new :ref:`Color<class_Color>` variable and sets its values
|
||||
Then it creates a new :ref:`Color <class_Color>` variable and sets its values
|
||||
according to the input file. If the ``use_red_anyway`` option is enabled, then
|
||||
it sets the color as a pure red instead.
|
||||
|
||||
@@ -329,7 +329,7 @@ it sets the color as a pure red instead.
|
||||
var material = SpatialMaterial.new()
|
||||
material.albedo_color = color
|
||||
|
||||
This part makes a new :ref:`SpatialMaterial<class_SpatialMaterial>` that is the
|
||||
This part makes a new :ref:`SpatialMaterial <class_SpatialMaterial>` that is the
|
||||
imported resource. We create a new instance of it and then set its albedo color
|
||||
as the value we got before.
|
||||
|
||||
@@ -340,12 +340,12 @@ as the value we got before.
|
||||
This is the last part and quite an important one, because here we save the made
|
||||
resource to the disk. The path of the saved file is generated and informed by
|
||||
the editor via the ``save_path`` parameter. Note that this comes **without** the
|
||||
extension, so we add it using :ref:`string formatting<doc_gdscript_printf>`. For
|
||||
extension, so we add it using :ref:`string formatting <doc_gdscript_printf>`. For
|
||||
this we call the ``get_save_extension`` method that we defined earlier, so we
|
||||
can be sure that they won't get out of sync.
|
||||
|
||||
We also return the result from the
|
||||
:ref:`ResourceSaver.save<class_ResourceSaver_save>` method, so if there's an
|
||||
:ref:`ResourceSaver.save() <class_ResourceSaver_method_save>` method, so if there's an
|
||||
error in this step, the editor will know about it.
|
||||
|
||||
Platform variants and generated files
|
||||
@@ -358,7 +358,7 @@ method. Both of them are arrays that you can fill with information.
|
||||
|
||||
The ``r_platform_variants`` argument is used if you need to import the resource
|
||||
differently depending on the target platform. While it's called *platform*
|
||||
variants, it is based on the presence of :ref:`feature tags<doc_feature_tags>`,
|
||||
variants, it is based on the presence of :ref:`feature tags <doc_feature_tags>`,
|
||||
so even the same platform can have multiple variants depending on the setup.
|
||||
|
||||
To import a platform variant, you need to save it with the feature tag before
|
||||
|
||||
@@ -63,8 +63,8 @@ inherit from :ref:`class_EditorPlugin`.
|
||||
|
||||
It's important to deal with initialization and clean-up of resources.
|
||||
A good practice is to use the virtual function
|
||||
:ref:`_enter_tree() <class_Node__enter_tree>` to initialize your plugin and
|
||||
:ref:`_exit_tree() <class_Node__exit_tree>` to clean it up. You can delete the
|
||||
:ref:`_enter_tree() <class_Node_method__enter_tree>` to initialize your plugin and
|
||||
:ref:`_exit_tree() <class_Node_method__exit_tree>` to clean it up. You can delete the
|
||||
default GDScript template from your file and replace it with the following
|
||||
structure:
|
||||
|
||||
@@ -94,7 +94,7 @@ projects. A good solution to this is to make a plugin that adds a node with a
|
||||
custom behavior.
|
||||
|
||||
To create a new node type, you can use the function
|
||||
:ref:`add_custom_type() <class_EditorPlugin_add_custom_type>` from the
|
||||
:ref:`add_custom_type() <class_EditorPlugin_method_add_custom_type>` from the
|
||||
:ref:`class_EditorPlugin` class. This function can add new types to the editor
|
||||
(nodes or resources). However, before you can create the type, you need a script
|
||||
that will act as the logic for the type. While that script doesn't have to use
|
||||
@@ -188,7 +188,7 @@ Also, don't forget to add some text to your button.
|
||||
|
||||
Save this scene as ``my_dock.tscn``. Now, we need to grab the scene we created
|
||||
then add it as a dock in the editor. For this, you can rely on the function
|
||||
:ref:`add_control_to_dock() <class_EditorPlugin_add_control_to_dock>` from the
|
||||
:ref:`add_control_to_dock() <class_EditorPlugin_method_add_control_to_dock>` from the
|
||||
:ref:`EditorPlugin <class_EditorPlugin>` class.
|
||||
|
||||
You need to select a dock position and define the control to add
|
||||
|
||||
Reference in New Issue
Block a user