Documentation
¶
Overview ¶
[graphics.gd/classdb/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.
EditorImportPlugins work by associating with specific file extensions and a resource type. See [Interface.GetRecognizedExtensions] and [Interface.GetResourceType]. They may optionally specify some import presets that affect the import process. EditorImportPlugins are responsible for creating the resources and saving them in the .godot/imported directory (see graphics.gd/classdb/ProjectSettings "application/config/use_hidden_project_data_directory").
Below is an example EditorImportPlugin that imports a graphics.gd/classdb/Mesh from a file with the extension ".special" or ".spec":
package main import ( "graphics.gd/classdb/ArrayMesh" "graphics.gd/classdb/EditorImportPlugin" "graphics.gd/classdb/FileAccess" "graphics.gd/classdb/ResourceSaver" ) type MySpecialPlugin struct { EditorImportPlugin.Extension[MySpecialPlugin] } func (m *MySpecialPlugin) GetImporterName() string { return "my.special.plugin" } func (m *MySpecialPlugin) GetVisibleName() string { return "Special Mesh" } func (m *MySpecialPlugin) GetRecognizedExtensions() []string { return []string{"special", "spec"} } func (m *MySpecialPlugin) GetSaveExtension() string { return "mesh" } func (m *MySpecialPlugin) GetResourceType() string { return "Mesh" } func (m *MySpecialPlugin) GetPresetCount() int { return 1 } func (m *MySpecialPlugin) GetPresetName(presetIndex int) string { return "Default" } func (m *MySpecialPlugin) GetImportOptions(path string, presetIndex int) []map[any]any { return []map[any]any{ { "name": "my_option", "default_value": false, }, } } func (m *MySpecialPlugin) Import(sourceFile, savePath string, options map[any]any, platformVariants, genFiles []string) error { var file = FileAccess.Open(sourceFile, FileAccess.Read) if err := file.GetError(); err != nil { return err } var mesh = ArrayMesh.New() // Fill the Mesh with data read in "file", left as an exercise to the reader. var filename = savePath + "." + m.GetSaveExtension() return ResourceSaver.Save(mesh.AsResource(), filename, 0) }
To use graphics.gd/classdb/EditorImportPlugin, register it using the graphics.gd/classdb/EditorPlugin.Instance.AddImportPlugin method first.
Index ¶
- type Advanced
- type Any
- type Expanded
- type Extension
- type ID
- type Implementation
- type Instance
- func (self Instance) AppendImportExternalResource(path string) error
- func (self Instance) AsEditorImportPlugin() Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) AsRefCounted() [1]gd.RefCounted
- func (self Instance) AsResourceImporter() ResourceImporter.Instance
- func (self Instance) ID() ID
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) Virtual(name string) reflect.Value
- type Interface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Advanced ¶
type Advanced = class
Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.
type Expanded ¶
type Expanded [1]gdclass.EditorImportPlugin
func (Expanded) AppendImportExternalResource ¶
func (self Expanded) AppendImportExternalResource(path string, custom_options map[string]interface{}, custom_importer string, generator_parameters any) error
This function can only be called during the [Interface.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 'custom_options'. Additionally, in cases where multiple importers can handle a file, the 'custom_importer' can be specified to force a specific one. This function performs a resource import and returns immediately with a success or error code. 'generator_parameters' defines optional extra metadata which will be stored as generator_parameters in the remap section of the .import file, for example to store a md5 hash of the source data.
type Extension ¶
Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this [Extension]See Interface for methods that can be overridden by T.
func (*Extension[T]) AsEditorImportPlugin ¶
func (*Extension[T]) AsRefCounted ¶
func (self *Extension[T]) AsRefCounted() [1]gd.RefCounted
func (*Extension[T]) AsResourceImporter ¶
func (self *Extension[T]) AsResourceImporter() ResourceImporter.Instance
type ID ¶
ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.
type Implementation ¶
type Implementation = implementation
Implementation implements Interface with empty methods.
type Instance ¶
type Instance [1]gdclass.EditorImportPlugin
Instance of the class with convieniently typed arguments and results.
var Nil Instance
Nil is a nil/null instance of the class. Equivalent to the zero value.
func (Instance) AppendImportExternalResource ¶
This function can only be called during the [Interface.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 'custom_options'. Additionally, in cases where multiple importers can handle a file, the 'custom_importer' can be specified to force a specific one. This function performs a resource import and returns immediately with a success or error code. 'generator_parameters' defines optional extra metadata which will be stored as generator_parameters in the remap section of the .import file, for example to store a md5 hash of the source data.
func (Instance) AsEditorImportPlugin ¶
func (Instance) AsRefCounted ¶
func (self Instance) AsRefCounted() [1]gd.RefCounted
func (Instance) AsResourceImporter ¶
func (self Instance) AsResourceImporter() ResourceImporter.Instance
type Interface ¶
type Interface interface { // Gets the unique name of the importer. GetImporterName() string // 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". GetVisibleName() string // Gets the number of initial presets defined by the plugin. Use [Interface.GetImportOptions] to get the default options for the preset and [Interface.GetPresetName] to get the name of the preset. GetPresetCount() int // Gets the name of the options preset at this index. GetPresetName(preset_index int) string // Gets the list of file extensions to associate with this loader (case-insensitive). e.g. ["obj"]. GetRecognizedExtensions() []string // Gets the options and default values for the preset at this index. Returns an Array of Dictionaries with the following keys: name, default_value, property_hint (optional), hint_string (optional), usage (optional). GetImportOptions(path string, preset_index int) [][]struct { Name string "gd:\"name\"" DefaultValue interface{} "gd:\"default_value\"" PropertyHint int "gd:\"property_hint\"" HintString string "gd:\"hint_string\"" Usage int "gd:\"usage\"" } // Gets the extension used to save this resource in the .godot/imported directory (see [graphics.gd/classdb/ProjectSettings] "application/config/use_hidden_project_data_directory"). GetSaveExtension() string // Gets the Godot resource type associated with this loader. e.g. "Mesh" or "Animation". GetResourceType() string // Gets the priority of this plugin for the recognized extension. Higher priority plugins will be preferred. The default priority is 1.0. GetPriority() Float.X // Gets the order of this importer to be run when importing resources. Importers with lower 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 0 unless overridden by a specific importer. See [ResourceImporter.ImportOrder] for some predefined values. GetImportOrder() int // Gets the format version of this importer. Increment this version when making incompatible changes to the format of the imported resources. GetFormatVersion() int // 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. // // // // [gdscript] // // func _get_option_visibility(option, options): // // # Only show the lossy quality setting if the compression mode is set to "Lossy". // // if option == "compress/lossy_quality" and options.has("compress/mode"): // // return int(options["compress/mode"]) == COMPRESS_LOSSY # This is a constant that you set // // // // return true // // [/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/lossy_quality" && options.ContainsKey("compress/mode")) // // { // // return (int)options["compress/mode"] == CompressLossy; // This is a constant you set // // } // // // // return true; // // } // // [/csharp] // // // // Returns true to make all options always visible. GetOptionVisibility(path string, option_name string, options map[string]interface{}) bool // Imports 'source_file' into 'save_path' with the import 'options' specified. The 'platform_variants' and 'gen_files' 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. Import(source_file string, save_path string, options map[string]interface{}, platform_variants []string, gen_files []string) error // Tells whether this importer can be run in parallel on threads, or, on the contrary, it's only safe for the editor to call it from the main thread, for one file at a time. // // If this method is not overridden, it will return false by default. // // If this importer's implementation is thread-safe and can be run in parallel, override this with true to optimize for concurrency. CanImportThreaded() bool }