Godot Engine: 속성 패널(Inspector plugins) 플러그인

공식 문서 Inspector plugins를 참조하여 Godot에서 속성 패널(Inspector plugins) 플러그인(Inspector plugins)은 특수 편집기 플러그인입니다.
단계 생성하기
  • 1. plugin을 생성합니다.cfg
  • 2. EditorPlugin 스크립트
  • 3. EditorInspectorPlugin 스크립트
  • 4. EditorProperty 스크립트


  • 1. 플러그인을 만듭니다.cfg
    일반적인 편집기 플러그인과 마찬가지로 Godot Engine: 편집기 플러그인 (Editor Plugin) 개발의 Hello World 를 보십시오.
    2. EditorPlugin 스크립트
    tool
    extends EditorPlugin
    var plugin
    
    func _enter_tree():
        plugin = preload("res://addons/MyPlugin/MyInspectorPlugin.gd").new()
        add_inspector_plugin(plugin)
        
    func _exit_tree():
        remove_inspector_plugin(plugin)
    

    참고:
  • EditorInspectorPluginReference에 계승되기 때문에 장면을 만들고 instance()류의 실례화를 사용할 수 없으며 스크립트 자원을 직접 불러오고 new()류의 실례화를 사용해야 한다.
  • add_inspector_plugin\remove_inspector_plugin를 통해 플러그인을 Inspector에 놓는다.

  • 3. EditorInspectorPlugin 스크립트
    # MyInspectorPlugin.gd
    extends EditorInspectorPlugin
    
    
    func can_handle(object):
        return true
    
    
    func parse_property(object, type, path, hint, hint_text, usage):
        if type == TYPE_INT:
            add_property_editor(path, MyIntEditor.new())
            return true
        else:
            return false
    
    EditorInspectorPlugin 주로 두 가지 일을 한다
  • can_handle를 통해 목표 유형을 필터한다. 예를 들어:
  • func can_handle(object):
    	return object is GridMap
    
  • parse_property를 통해 목표 속성을 필터하고 true로 돌아가면 기본 속성 편집기를 표시하지 않습니다.되돌아오기false는 기본 속성 편집기 앞에 사용자 정의 편집기를 삽입합니다
  • type의 유형
    enum Variant.Type:
       TYPE_NIL = 0 --- Variable is null.
       TYPE_BOOL = 1 --- Variable is of type bool.
       TYPE_INT = 2 --- Variable is of type int.
       TYPE_REAL = 3 --- Variable is of type float (real).
       TYPE_STRING = 4 --- Variable is of type String.
       TYPE_VECTOR2 = 5 --- Variable is of type Vector2.
       TYPE_VECTOR2I = 6 --- Variable is of type Vector2i.
       TYPE_RECT2 = 7 --- Variable is of type Rect2.
       TYPE_RECT2I = 8 --- Variable is of type Rect2i.
       TYPE_VECTOR3 = 9 --- Variable is of type Vector3.
       TYPE_VECTOR3I = 10 --- Variable is of type Vector3i.
       TYPE_TRANSFORM2D = 11 --- Variable is of type Transform2D.
       TYPE_PLANE = 12 --- Variable is of type Plane.
       TYPE_QUAT = 13 --- Variable is of type Quat.
       TYPE_AABB = 14 --- Variable is of type AABB.
       TYPE_BASIS = 15 --- Variable is of type Basis.
       TYPE_TRANSFORM = 16 --- Variable is of type Transform.
       TYPE_COLOR = 17 --- Variable is of type Color.
       TYPE_STRING_NAME = 18 --- Variable is of type StringName.
       TYPE_NODE_PATH = 19 --- Variable is of type NodePath.
       TYPE_RID = 20 --- Variable is of type RID.
       TYPE_OBJECT = 21 --- Variable is of type Object.
       TYPE_CALLABLE = 22 --- Variable is of type Callable.
       TYPE_SIGNAL = 23 --- Variable is of type Signal.
       TYPE_DICTIONARY = 24 --- Variable is of type Dictionary.
       TYPE_ARRAY = 25 --- Variable is of type Array.
       TYPE_RAW_ARRAY = 26 --- Variable is of type PackedByteArray.
       TYPE_INT32_ARRAY = 27 --- Variable is of type PackedInt32Array.
       TYPE_INT64_ARRAY = 28 --- Variable is of type PackedInt64Array.
       TYPE_FLOAT32_ARRAY = 29 --- Variable is of type PackedFloat32Array.
       TYPE_FLOAT64_ARRAY = 30 --- Variable is of type PackedFloat64Array.
       TYPE_STRING_ARRAY = 31 --- Variable is of type PackedStringArray.
       TYPE_VECTOR2_ARRAY = 32 --- Variable is of type PackedVector2Array.
       TYPE_VECTOR3_ARRAY = 33 --- Variable is of type PackedVector3Array.
       TYPE_COLOR_ARRAY = 34 --- Variable is of type PackedColorArray.
       TYPE_MAX = 35 --- Represents the size of the Variant.Type enum.
    

    4. EditorProperty 스크립트
    # MyIntEditor.gd
    extends EditorProperty
    class_name MyIntEditor
    
    
    var updating = false
    var spin = EditorSpinSlider.new()
    func _init():
       add_child(spin)
       add_focusable(spin)
       spin.set_min(0)
       spin.set_max(1000)
       spin.connect("value_changed", self, "_spin_changed")
    
    
    func _spin_changed(value):
        if (updating):
            return
        emit_changed(get_edited_property(), value)
    
    func update_property():
        var new_value = get_edited_object()[get_edited_property()]
        updating = true
        spin.set_value(new_value)
        updating = false
    

    이 단계는 특정 속성을 정의하는 편집기입니다

    좋은 웹페이지 즐겨찾기