2017-09-12 22:42:36 +02:00
<?xml version="1.0" encoding="UTF-8" ?>
2023-07-06 10:08:05 +02:00
<class name= "EditorImportPlugin" inherits= "ResourceImporter" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation= "../class.xsd" >
2017-09-12 22:42:36 +02:00
<brief_description >
2017-09-15 22:32:02 +02:00
Registers a custom resource importer in the editor. Use the class to parse any file and import it as a new resource type.
2017-09-12 22:42:36 +02:00
</brief_description>
<description >
2021-10-15 14:30:58 +02:00
[EditorImportPlugin]s provide a way to extend the editor's resource import functionality. Use them to import resources from custom files or to provide alternatives to the editor's existing importers.
2021-10-13 22:56:18 +02:00
EditorImportPlugins work by associating with specific file extensions and a resource type. See [method _get_recognized_extensions] and [method _get_resource_type]. They may optionally specify some import presets that affect the import process. EditorImportPlugins are responsible for creating the resources and saving them in the [code].godot/imported[/code] directory (see [member ProjectSettings.application/config/use_hidden_project_data_directory]).
2017-09-15 22:32:02 +02:00
Below is an example EditorImportPlugin that imports a [Mesh] from a file with the extension ".special" or ".spec":
2020-09-13 14:45:36 +02:00
[codeblocks]
[gdscript]
2022-09-21 22:49:03 +02:00
@tool
2017-09-15 22:32:02 +02:00
extends EditorImportPlugin
2021-05-15 23:48:59 +02:00
func _get_importer_name():
2017-09-15 22:32:02 +02:00
return "my.special.plugin"
2021-05-15 23:48:59 +02:00
func _get_visible_name():
2021-02-09 14:30:27 +01:00
return "Special Mesh"
2017-09-15 22:32:02 +02:00
2021-05-15 23:48:59 +02:00
func _get_recognized_extensions():
2017-09-15 22:32:02 +02:00
return ["special", "spec"]
2021-05-15 23:48:59 +02:00
func _get_save_extension():
2017-09-15 22:32:02 +02:00
return "mesh"
2021-05-15 23:48:59 +02:00
func _get_resource_type():
2017-09-15 22:32:02 +02:00
return "Mesh"
2021-05-15 23:48:59 +02:00
func _get_preset_count():
2017-09-15 22:32:02 +02:00
return 1
2023-06-28 09:27:38 +02:00
func _get_preset_name(preset_index):
2017-09-15 22:32:02 +02:00
return "Default"
2023-06-28 09:27:38 +02:00
func _get_import_options(path, preset_index):
2017-09-15 22:32:02 +02:00
return [{"name": "my_option", "default_value": false}]
2021-05-15 23:48:59 +02:00
func _import(source_file, save_path, options, platform_variants, gen_files):
2023-01-30 15:21:36 +01:00
var file = FileAccess.open(source_file, FileAccess.READ)
if file == null:
2017-09-15 22:32:02 +02:00
return FAILED
2020-09-13 14:45:36 +02:00
var mesh = ArrayMesh.new()
# Fill the Mesh with data read in "file", left as an exercise to the reader.
2017-09-15 22:32:02 +02:00
2021-05-15 23:48:59 +02:00
var filename = save_path + "." + _get_save_extension()
2022-09-21 22:26:48 +02:00
return ResourceSaver.save(mesh, filename)
2020-09-13 14:45:36 +02:00
[/gdscript]
[csharp]
using Godot;
2023-01-31 18:21:09 +01:00
public partial class MySpecialPlugin : EditorImportPlugin
2020-09-13 14:45:36 +02:00
{
2023-01-31 18:21:09 +01:00
public override string _GetImporterName()
2020-09-13 14:45:36 +02:00
{
return "my.special.plugin";
}
2023-01-31 18:21:09 +01:00
public override string _GetVisibleName()
2020-09-13 14:45:36 +02:00
{
2021-02-09 14:30:27 +01:00
return "Special Mesh";
2020-09-13 14:45:36 +02:00
}
2023-01-31 18:21:09 +01:00
public override string[] _GetRecognizedExtensions()
2020-09-13 14:45:36 +02:00
{
2023-01-31 18:21:09 +01:00
return new string[] { "special", "spec" };
2020-09-13 14:45:36 +02:00
}
2023-01-31 18:21:09 +01:00
public override string _GetSaveExtension()
2020-09-13 14:45:36 +02:00
{
return "mesh";
}
2023-01-31 18:21:09 +01:00
public override string _GetResourceType()
2020-09-13 14:45:36 +02:00
{
return "Mesh";
}
2023-01-31 18:21:09 +01:00
public override int _GetPresetCount()
2020-09-13 14:45:36 +02:00
{
return 1;
}
2023-01-31 18:21:09 +01:00
public override string _GetPresetName(int presetIndex)
2020-09-13 14:45:36 +02:00
{
return "Default";
}
2023-01-31 18:21:09 +01:00
public override Godot.Collections.Array< Godot.Collections.Dictionary> _GetImportOptions(string path, int presetIndex)
2020-09-13 14:45:36 +02:00
{
2023-01-31 18:21:09 +01:00
return new Godot.Collections.Array< Godot.Collections.Dictionary>
{
new Godot.Collections.Dictionary
{
{ "name", "myOption" },
2023-06-01 19:38:20 +02:00
{ "default_value", false },
2023-01-31 18:21:09 +01:00
}
};
2020-09-13 14:45:36 +02:00
}
2023-01-31 18:21:09 +01:00
public override int _Import(string sourceFile, string savePath, Godot.Collections.Dictionary options, Godot.Collections.Array< string> platformVariants, Godot.Collections.Array< string> genFiles)
2020-09-13 14:45:36 +02:00
{
2023-01-31 18:21:09 +01:00
using var file = FileAccess.Open(sourceFile, FileAccess.ModeFlags.Read);
if (file.GetError() != Error.Ok)
2020-09-13 14:45:36 +02:00
{
return (int)Error.Failed;
}
var mesh = new ArrayMesh();
// Fill the Mesh with data read in "file", left as an exercise to the reader.
2023-01-31 18:21:09 +01:00
string filename = $"{savePath}.{_GetSaveExtension()}";
2022-09-21 22:26:48 +02:00
return (int)ResourceSaver.Save(mesh, filename);
2020-09-13 14:45:36 +02:00
}
}
[/csharp]
[/codeblocks]
2021-10-15 14:30:58 +02:00
To use [EditorImportPlugin], register it using the [method EditorPlugin.add_import_plugin] method first.
2017-09-12 22:42:36 +02:00
</description>
<tutorials >
2021-11-15 10:43:07 +01:00
<link title= "Import plugins" > $DOCS_URL/tutorials/plugins/editor/import_plugins.html</link>
2017-09-12 22:42:36 +02:00
</tutorials>
<methods >
2021-08-22 03:52:44 +02:00
<method name= "_get_import_options" qualifiers= "virtual const" >
2022-08-05 03:41:48 +02:00
<return type= "Dictionary[]" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "path" type= "String" />
<param index= "1" name= "preset_index" type= "int" />
2017-09-12 22:42:36 +02:00
<description >
2019-06-22 01:04:47 +02:00
Gets the options and default values for the preset at this index. Returns an Array of Dictionaries with the following keys: [code]name[/code], [code]default_value[/code], [code]property_hint[/code] (optional), [code]hint_string[/code] (optional), [code]usage[/code] (optional).
2017-09-12 22:42:36 +02:00
</description>
</method>
2021-08-22 03:52:44 +02:00
<method name= "_get_import_order" qualifiers= "virtual const" >
2021-07-30 15:28:05 +02:00
<return type= "int" />
2018-02-13 14:59:56 +01:00
<description >
2021-07-23 12:10:32 +02:00
Gets the order of this importer to be run when importing resources. Importers with [i]lower[/i] import orders will be called first, and higher values will be called later. Use this to ensure the importer runs after the dependencies are already imported. The default import order is [code]0[/code] unless overridden by a specific importer. See [enum ResourceImporter.ImportOrder] for some predefined values.
2018-02-13 14:59:56 +01:00
</description>
</method>
2021-08-22 03:52:44 +02:00
<method name= "_get_importer_name" qualifiers= "virtual const" >
2021-07-30 15:28:05 +02:00
<return type= "String" />
2017-09-12 22:42:36 +02:00
<description >
2019-06-22 01:04:47 +02:00
Gets the unique name of the importer.
2017-09-12 22:42:36 +02:00
</description>
</method>
2021-08-22 03:52:44 +02:00
<method name= "_get_option_visibility" qualifiers= "virtual const" >
2021-07-30 15:28:05 +02:00
<return type= "bool" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "path" type= "String" />
<param index= "1" name= "option_name" type= "StringName" />
<param index= "2" name= "options" type= "Dictionary" />
2017-09-12 22:42:36 +02:00
<description >
2020-07-18 17:17:00 +02:00
This method can be overridden to hide specific import options if conditions are met. This is mainly useful for hiding options that depend on others if one of them is disabled. For example:
2020-09-13 14:45:36 +02:00
[codeblocks]
[gdscript]
2021-05-15 23:48:59 +02:00
func _get_option_visibility(option, options):
2020-07-18 17:17:00 +02:00
# Only show the lossy quality setting if the compression mode is set to "Lossy".
if option == "compress/lossy_quality" and options.has("compress/mode"):
2020-09-13 14:45:36 +02:00
return int(options["compress/mode"]) == COMPRESS_LOSSY # This is a constant that you set
2020-07-18 17:17:00 +02:00
return true
2020-09-13 14:45:36 +02:00
[/gdscript]
[csharp]
2023-06-01 19:38:20 +02:00
public void _GetOptionVisibility(string option, Godot.Collections.Dictionary options)
2020-09-13 14:45:36 +02:00
{
// Only show the lossy quality setting if the compression mode is set to "Lossy".
2023-06-01 19:38:20 +02:00
if (option == "compress/lossy_quality" & & options.ContainsKey("compress/mode"))
2020-09-13 14:45:36 +02:00
{
2023-06-01 19:38:20 +02:00
return (int)options["compress/mode"] == CompressLossy; // This is a constant you set
2020-09-13 14:45:36 +02:00
}
return true;
}
[/csharp]
[/codeblocks]
2022-01-02 18:32:49 +01:00
Returns [code]true[/code] to make all options always visible.
2017-09-12 22:42:36 +02:00
</description>
</method>
2021-08-22 03:52:44 +02:00
<method name= "_get_preset_count" qualifiers= "virtual const" >
2021-07-30 15:28:05 +02:00
<return type= "int" />
2017-09-12 22:42:36 +02:00
<description >
2021-05-15 23:48:59 +02:00
Gets the number of initial presets defined by the plugin. Use [method _get_import_options] to get the default options for the preset and [method _get_preset_name] to get the name of the preset.
2017-09-12 22:42:36 +02:00
</description>
</method>
2021-08-22 03:52:44 +02:00
<method name= "_get_preset_name" qualifiers= "virtual const" >
2021-07-30 15:28:05 +02:00
<return type= "String" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "preset_index" type= "int" />
2017-09-12 22:42:36 +02:00
<description >
2019-06-22 01:04:47 +02:00
Gets the name of the options preset at this index.
2017-09-12 22:42:36 +02:00
</description>
</method>
2021-08-22 03:52:44 +02:00
<method name= "_get_priority" qualifiers= "virtual const" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
2018-02-13 14:59:56 +01:00
<description >
2019-06-29 15:24:23 +02:00
Gets the priority of this plugin for the recognized extension. Higher priority plugins will be preferred. The default priority is [code]1.0[/code].
2018-02-13 14:59:56 +01:00
</description>
</method>
2021-08-22 03:52:44 +02:00
<method name= "_get_recognized_extensions" qualifiers= "virtual const" >
<return type= "PackedStringArray" />
2017-09-12 22:42:36 +02:00
<description >
2019-06-22 01:04:47 +02:00
Gets the list of file extensions to associate with this loader (case-insensitive). e.g. [code]["obj"][/code].
2017-09-12 22:42:36 +02:00
</description>
</method>
2021-08-22 03:52:44 +02:00
<method name= "_get_resource_type" qualifiers= "virtual const" >
2021-07-30 15:28:05 +02:00
<return type= "String" />
2017-09-12 22:42:36 +02:00
<description >
2019-06-22 01:04:47 +02:00
Gets the Godot resource type associated with this loader. e.g. [code]"Mesh"[/code] or [code]"Animation"[/code].
2017-09-12 22:42:36 +02:00
</description>
</method>
2021-08-22 03:52:44 +02:00
<method name= "_get_save_extension" qualifiers= "virtual const" >
2021-07-30 15:28:05 +02:00
<return type= "String" />
2017-09-12 22:42:36 +02:00
<description >
2021-10-13 22:56:18 +02:00
Gets the extension used to save this resource in the [code].godot/imported[/code] directory (see [member ProjectSettings.application/config/use_hidden_project_data_directory]).
2017-09-12 22:42:36 +02:00
</description>
</method>
2021-08-22 03:52:44 +02:00
<method name= "_get_visible_name" qualifiers= "virtual const" >
2021-07-30 15:28:05 +02:00
<return type= "String" />
2017-09-12 22:42:36 +02:00
<description >
2021-02-09 14:30:27 +01:00
Gets the name to display in the import window. You should choose this name as a continuation to "Import as", e.g. "Import as Special Mesh".
2017-09-12 22:42:36 +02:00
</description>
</method>
2021-08-22 03:52:44 +02:00
<method name= "_import" qualifiers= "virtual const" >
2023-01-15 20:33:20 +01:00
<return type= "int" enum= "Error" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "source_file" type= "String" />
<param index= "1" name= "save_path" type= "String" />
<param index= "2" name= "options" type= "Dictionary" />
2022-08-31 19:24:04 +02:00
<param index= "3" name= "platform_variants" type= "String[]" />
<param index= "4" name= "gen_files" type= "String[]" />
2017-09-12 22:42:36 +02:00
<description >
2022-08-12 18:07:53 +02:00
Imports [param source_file] into [param save_path] with the import [param options] specified. The [param platform_variants] and [param gen_files] arrays will be modified by this function.
2020-07-18 17:17:00 +02:00
This method must be overridden to do the actual importing work. See this class' description for an example of overriding this method.
2017-09-12 22:42:36 +02:00
</description>
</method>
2023-01-31 15:59:52 +01:00
<method name= "append_import_external_resource" >
<return type= "int" enum= "Error" />
<param index= "0" name= "path" type= "String" />
<param index= "1" name= "custom_options" type= "Dictionary" default= "{}" />
<param index= "2" name= "custom_importer" type= "String" default= """" />
2023-02-02 22:41:04 +01:00
<param index= "3" name= "generator_parameters" type= "Variant" default= "null" />
2023-01-31 15:59:52 +01:00
<description >
2023-02-02 22:41:04 +01:00
This function can only be called during the [method _import] callback and it allows manually importing resources from it. This is useful when the imported file generates external resources that require importing (as example, images). Custom parameters for the ".import" file can be passed via the [param custom_options]. Additionally, in cases where multiple importers can handle a file, the [param custom_importer] ca be specified to force a specific one. This function performs a resource import and returns immediately with a success or error code. [param generator_parameters] defines optional extra metadata which will be stored as [code]generator_parameters[/code] in the [code]remap[/code] section of the [code].import[/code] file, for example to store a md5 hash of the source data.
2023-01-31 15:59:52 +01:00
</description>
</method>
2017-09-12 22:42:36 +02:00
</methods>
</class>