EditorImportPlugin

Inherits: ResourceImporter < Reference < Object

类别: 核心

简要说明

在编辑器中注册自定义资源导入程序。使用该类分析任何文件并将其作为新资源类型导入。

方法

Array

get_import_options ( int preset ) virtual

int

get_import_order ( ) virtual

String

get_importer_name ( ) virtual

bool

get_option_visibility ( String option, Dictionary options ) virtual

int

get_preset_count ( ) virtual

String

get_preset_name ( int preset ) virtual

float

get_priority ( ) virtual

Array

get_recognized_extensions ( ) virtual

String

get_resource_type ( ) virtual

String

get_save_extension ( ) virtual

String

get_visible_name ( ) virtual

int

import ( String source_file, String save_path, Dictionary options, Array platform_variants, Array gen_files ) virtual

描述

editorimportplugins提供了一种扩展编辑器资源导入功能的方法。使用它们从自定义文件中导入资源或提供编辑器现有导入器的替代项。注册您的 EditorPlugin 具有 EditorPlugin.add_import_plugin .

editorimportplugins通过与特定的文件扩展名和资源类型关联来工作。见 get_recognized_extensionsget_resource_type . 它们可以选择指定一些影响导入过程的导入预设。editorimportplugins负责创建资源并将其保存在 .import 目录。

下面是一个导入 Mesh 来自扩展名为“.special”或“.spec”的文件:

tool
extends EditorImportPlugin

func get_importer_name():
    return "my.special.plugin"

func get_visible_name():
    return "Special Mesh Importer"

func get_recognized_extensions():
    return ["special", "spec"]

func get_save_extension():
    return "mesh"

func get_resource_type():
    return "Mesh"

func get_preset_count():
    return 1

func get_preset_name(i):
    return "Default"

func get_import_options(i):
    return [{"name": "my_option", "default_value": false}]

func import(source_file, save_path, options, platform_variants, gen_files):
    var file = File.new()
    if file.open(source_file, File.READ) != OK:
        return FAILED

    var mesh = Mesh.new()
    # Fill the Mesh with data read in "file", left as an exercise to the reader

    var filename = save_path + "." + get_save_extension()
    ResourceSaver.save(filename, mesh)
    return OK

方法说明

  • Array get_import_options ( int preset ) virtual

获取此索引处预设的选项和默认值。返回具有以下键的字典数组: namedefault_valueproperty_hint (可选) hint_string (可选) usage (可选)。

  • int get_import_order ( ) virtual

获取导入资源时要运行的导入程序的顺序。稍后将调用更高的值。使用此选项可确保导入程序在已导入依赖项之后运行。

  • String get_importer_name ( ) virtual

获取导入程序的唯一名称。

  • int get_preset_count ( ) virtual

获取插件定义的初始预设数。使用 get_import_options 获取预设和 get_preset_name 获取预设的名称。

  • String get_preset_name ( int preset ) virtual

获取此索引处预设的选项的名称。

  • float get_priority ( ) virtual

获取此插件对于已识别扩展的优先级。优先级别更高的插件将是首选。默认优先级为 1.0 .

  • Array get_recognized_extensions ( ) virtual

获取要与此加载程序关联的文件扩展名列表(不区分大小写)。例如 ["obj"] .

  • String get_resource_type ( ) virtual

获取与此加载程序关联的godot资源类型。例如 "Mesh""Animation" .

  • String get_save_extension ( ) virtual

获取用于将此资源保存到 .import 目录。

  • String get_visible_name ( ) virtual

获取要在导入窗口中显示的名称。