inspector_plugins.rst 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. .. _doc_inspector_plugins:
  2. Inspector Plugins
  3. =====================
  4. Introduction
  5. ------------
  6. Godot 3.1 comes with a new inspector. Adding plugins to it is now possible.
  7. This tutorial will explain the process.
  8. Inspector Plugin
  9. ----------------
  10. This short tutorial will explain how to make a simple value editor.
  11. Create an EditorInspectorPlugin first. This is needed to initialize your plugin.
  12. .. tabs::
  13. .. code-tab:: gdscript GDScript
  14. # MyEditorPlugin.gd
  15. extends EditorInspectorPlugin
  16. func can_handle(object):
  17. # if only editing a specific type
  18. # return object is TheTypeIWant
  19. # if everything is supported
  20. return true
  21. func parse_property(object,type,path,hint,hint_text,usage):
  22. if (type==TYPE_INT):
  23. add_custom_property_editor(path,MyEditor.new())
  24. return true # I want this one
  25. else:
  26. return false
  27. Editor
  28. ------
  29. Here is an editor for editing integers
  30. .. tabs::
  31. .. code-tab:: gdscript GDScript
  32. # MyEditor.gd
  33. class_name MyEditor
  34. var updating = false
  35. func _spin_changed(value):
  36. if (updating):
  37. return
  38. emit_changed( get_property(), value )
  39. func update_property():
  40. var new_value = get_edited_object()[ get_edited_property() ]
  41. updating=true
  42. spin.set_value( new_value )
  43. updating=false
  44. var spin = EditorSpinSlider.new() # use the new spin slider
  45. func _init():
  46. # if you want to put the editor below the label
  47. # set_bottom_editor( spin )
  48. # else use:
  49. add_child( spin )
  50. # to remember focus when selected back
  51. add_focusable( spin )
  52. spin.set_min(0)
  53. spin.set_max(1000)
  54. spin.connect("value_changed",self,"_spin_changed")