Inspector插件

介绍

Godot3.1配备了新的检查员。现在可以向它添加插件了。

本教程将解释这个过程。

检查器插件

这个简短的教程将解释如何创建一个简单的值编辑器。首先创建一个editorInspectorPlugin。这是初始化插件所必需的。

# MyEditorPlugin.gd

extends EditorInspectorPlugin

func can_handle(object):
    # if only editing a specific type
    # return object is TheTypeIWant
    # if everything is supported
    return true

func parse_property(object,type,path,hint,hint_text,usage):
    if (type==TYPE_INT):
         add_custom_property_editor(path,MyEditor.new())
         return true # I want this one
    else:
         return false

编辑

这里有一个编辑整数的编辑器

# MyEditor.gd
class_name MyEditor

var updating = false

func _spin_changed(value):
    if (updating):
        return

    emit_changed( get_property(), value )

func update_property():
    var new_value = get_edited_object()[ get_edited_property() ]

    updating=true
    spin.set_value( new_value )
    updating=false

var spin = EditorSpinSlider.new() # use the new spin slider
func _init():
   # if you want to put the editor below the label
   #   set_bottom_editor( spin )
   # else use:
   add_child( spin )
   # to remember focus when selected back
   add_focusable( spin )
   spin.set_min(0)
   spin.set_max(1000)
   spin.connect("value_changed",self,"_spin_changed")