2017-09-12 20:42:36 +00:00
<?xml version="1.0" encoding="UTF-8" ?>
2020-02-01 01:03:48 +00:00
<class name= "EditorImportPlugin" inherits= "ResourceImporter" version= "4.0" >
2017-09-12 20:42:36 +00:00
<brief_description >
2017-09-15 20:32:02 +00: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 20:42:36 +00:00
</brief_description>
<description >
2017-09-15 20:32:02 +00:00
EditorImportPlugins 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. Register your [EditorPlugin] with [method EditorPlugin.add_import_plugin].
2021-05-15 21:48:59 +00: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.
2017-09-15 20:32:02 +00:00
Below is an example EditorImportPlugin that imports a [Mesh] from a file with the extension ".special" or ".spec":
2020-09-13 12:45:36 +00:00
[codeblocks]
[gdscript]
2017-09-15 20:32:02 +00:00
tool
extends EditorImportPlugin
2021-05-15 21:48:59 +00:00
func _get_importer_name():
2017-09-15 20:32:02 +00:00
return "my.special.plugin"
2021-05-15 21:48:59 +00:00
func _get_visible_name():
2021-02-09 13:30:27 +00:00
return "Special Mesh"
2017-09-15 20:32:02 +00:00
2021-05-15 21:48:59 +00:00
func _get_recognized_extensions():
2017-09-15 20:32:02 +00:00
return ["special", "spec"]
2021-05-15 21:48:59 +00:00
func _get_save_extension():
2017-09-15 20:32:02 +00:00
return "mesh"
2021-05-15 21:48:59 +00:00
func _get_resource_type():
2017-09-15 20:32:02 +00:00
return "Mesh"
2021-05-15 21:48:59 +00:00
func _get_preset_count():
2017-09-15 20:32:02 +00:00
return 1
2021-05-15 21:48:59 +00:00
func _get_preset_name(i):
2017-09-15 20:32:02 +00:00
return "Default"
2021-05-15 21:48:59 +00:00
func _get_import_options(i):
2017-09-15 20:32:02 +00:00
return [{"name": "my_option", "default_value": false}]
2021-05-15 21:48:59 +00:00
func _import(source_file, save_path, options, platform_variants, gen_files):
2017-10-24 16:12:43 +00:00
var file = File.new()
2018-07-19 13:24:31 +00:00
if file.open(source_file, File.READ) != OK:
2017-09-15 20:32:02 +00:00
return FAILED
2020-09-13 12:45:36 +00:00
var mesh = ArrayMesh.new()
# Fill the Mesh with data read in "file", left as an exercise to the reader.
2017-09-15 20:32:02 +00:00
2021-05-15 21:48:59 +00:00
var filename = save_path + "." + _get_save_extension()
2021-02-09 13:30:27 +00:00
return ResourceSaver.save(filename, mesh)
2020-09-13 12:45:36 +00:00
[/gdscript]
[csharp]
using Godot;
using System;
public class MySpecialPlugin : EditorImportPlugin
{
public override String GetImporterName()
{
return "my.special.plugin";
}
public override String GetVisibleName()
{
2021-02-09 13:30:27 +00:00
return "Special Mesh";
2020-09-13 12:45:36 +00:00
}
public override Godot.Collections.Array GetRecognizedExtensions()
{
return new Godot.Collections.Array{"special", "spec"};
}
public override String GetSaveExtension()
{
return "mesh";
}
public override String GetResourceType()
{
return "Mesh";
}
public override int GetPresetCount()
{
return 1;
}
public override String GetPresetName(int i)
{
return "Default";
}
public override Godot.Collections.Array GetImportOptions(int i)
{
return new Godot.Collections.Array{new Godot.Collections.Dictionary{{"name", "myOption"}, {"defaultValue", false}}};
}
2021-06-07 08:17:32 +00:00
public override int Import(String sourceFile, String savePath, Godot.Collections.Dictionary options, Godot.Collections.Array platformVariants, Godot.Collections.Array genFiles)
2020-09-13 12:45:36 +00:00
{
var file = new File();
if (file.Open(sourceFile, File.ModeFlags.Read) != Error.Ok)
{
return (int)Error.Failed;
}
var mesh = new ArrayMesh();
// Fill the Mesh with data read in "file", left as an exercise to the reader.
String filename = savePath + "." + GetSaveExtension();
2021-02-09 13:30:27 +00:00
return (int)ResourceSaver.Save(filename, mesh);
2020-09-13 12:45:36 +00:00
}
}
[/csharp]
[/codeblocks]
2017-09-12 20:42:36 +00:00
</description>
<tutorials >
2020-08-05 12:43:40 +00:00
<link title= "Import plugins" > https://docs.godotengine.org/en/latest/tutorials/plugins/editor/import_plugins.html</link>
2017-09-12 20:42:36 +00:00
</tutorials>
<methods >
2021-05-15 21:48:59 +00:00
<method name= "_get_import_options" qualifiers= "virtual" >
2017-09-12 20:42:36 +00:00
<return type= "Array" >
</return>
<argument index= "0" name= "preset" type= "int" >
</argument>
<description >
2019-06-21 23:04:47 +00: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 20:42:36 +00:00
</description>
</method>
2021-05-15 21:48:59 +00:00
<method name= "_get_import_order" qualifiers= "virtual" >
2018-02-13 13:59:56 +00:00
<return type= "int" >
</return>
<description >
2019-06-21 23:04:47 +00:00
Gets the order of this importer to be run when importing resources. Higher values will be called later. Use this to ensure the importer runs after the dependencies are already imported.
2018-02-13 13:59:56 +00:00
</description>
</method>
2021-05-15 21:48:59 +00:00
<method name= "_get_importer_name" qualifiers= "virtual" >
2017-09-12 20:42:36 +00:00
<return type= "String" >
</return>
<description >
2019-06-21 23:04:47 +00:00
Gets the unique name of the importer.
2017-09-12 20:42:36 +00:00
</description>
</method>
2021-05-15 21:48:59 +00:00
<method name= "_get_option_visibility" qualifiers= "virtual" >
2017-09-12 20:42:36 +00:00
<return type= "bool" >
</return>
<argument index= "0" name= "option" type= "String" >
</argument>
<argument index= "1" name= "options" type= "Dictionary" >
</argument>
<description >
2020-07-18 15:17:00 +00: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 12:45:36 +00:00
[codeblocks]
[gdscript]
2021-05-15 21:48:59 +00:00
func _get_option_visibility(option, options):
2020-07-18 15:17:00 +00: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 12:45:36 +00:00
return int(options["compress/mode"]) == COMPRESS_LOSSY # This is a constant that you set
2020-07-18 15:17:00 +00:00
return true
2020-09-13 12:45:36 +00:00
[/gdscript]
[csharp]
public void GetOptionVisibility(string option, Godot.Collections.Dictionary options)
{
// Only show the lossy quality setting if the compression mode is set to "Lossy".
if (option == "compress/lossyQuality" & & options.Contains("compress/mode"))
{
return (int)options["compress/mode"] == COMPRESS_LOSSY; // This is a constant you set
}
return true;
}
[/csharp]
[/codeblocks]
2020-07-18 15:17:00 +00:00
Return [code]true[/code] to make all options always visible.
2017-09-12 20:42:36 +00:00
</description>
</method>
2021-05-15 21:48:59 +00:00
<method name= "_get_preset_count" qualifiers= "virtual" >
2017-09-12 20:42:36 +00:00
<return type= "int" >
</return>
<description >
2021-05-15 21:48:59 +00: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 20:42:36 +00:00
</description>
</method>
2021-05-15 21:48:59 +00:00
<method name= "_get_preset_name" qualifiers= "virtual" >
2017-09-12 20:42:36 +00:00
<return type= "String" >
</return>
<argument index= "0" name= "preset" type= "int" >
</argument>
<description >
2019-06-21 23:04:47 +00:00
Gets the name of the options preset at this index.
2017-09-12 20:42:36 +00:00
</description>
</method>
2021-05-15 21:48:59 +00:00
<method name= "_get_priority" qualifiers= "virtual" >
2018-02-13 13:59:56 +00:00
<return type= "float" >
</return>
<description >
2019-06-29 13:24:23 +00: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 13:59:56 +00:00
</description>
</method>
2021-05-15 21:48:59 +00:00
<method name= "_get_recognized_extensions" qualifiers= "virtual" >
2017-09-12 20:42:36 +00:00
<return type= "Array" >
</return>
<description >
2019-06-21 23:04:47 +00:00
Gets the list of file extensions to associate with this loader (case-insensitive). e.g. [code]["obj"][/code].
2017-09-12 20:42:36 +00:00
</description>
</method>
2021-05-15 21:48:59 +00:00
<method name= "_get_resource_type" qualifiers= "virtual" >
2017-09-12 20:42:36 +00:00
<return type= "String" >
</return>
<description >
2019-06-21 23:04:47 +00:00
Gets the Godot resource type associated with this loader. e.g. [code]"Mesh"[/code] or [code]"Animation"[/code].
2017-09-12 20:42:36 +00:00
</description>
</method>
2021-05-15 21:48:59 +00:00
<method name= "_get_save_extension" qualifiers= "virtual" >
2017-09-12 20:42:36 +00:00
<return type= "String" >
</return>
<description >
2020-07-06 00:55:43 +00:00
Gets the extension used to save this resource in the [code].godot/imported[/code] directory.
2017-09-12 20:42:36 +00:00
</description>
</method>
2021-05-15 21:48:59 +00:00
<method name= "_get_visible_name" qualifiers= "virtual" >
2017-09-12 20:42:36 +00:00
<return type= "String" >
</return>
<description >
2021-02-09 13:30:27 +00: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 20:42:36 +00:00
</description>
</method>
2021-05-15 21:48:59 +00:00
<method name= "_import" qualifiers= "virtual" >
2017-09-12 20:42:36 +00:00
<return type= "int" >
</return>
<argument index= "0" name= "source_file" type= "String" >
</argument>
<argument index= "1" name= "save_path" type= "String" >
</argument>
<argument index= "2" name= "options" type= "Dictionary" >
</argument>
2018-12-27 10:10:09 +00:00
<argument index= "3" name= "platform_variants" type= "Array" >
2017-09-12 20:42:36 +00:00
</argument>
2018-12-27 10:10:09 +00:00
<argument index= "4" name= "gen_files" type= "Array" >
2017-09-12 20:42:36 +00:00
</argument>
<description >
2020-07-18 15:17:00 +00:00
Imports [code]source_file[/code] into [code]save_path[/code] with the import [code]options[/code] specified. The [code]platform_variants[/code] and [code]gen_files[/code] arrays will be modified by this function.
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 20:42:36 +00:00
</description>
</method>
</methods>
<constants >
</constants>
</class>