Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

메인 씬 플러그인 만들기

이 튜토리얼에서 다루는 내용

메인 화면 플러그인을 사용하면 편집기 중앙 부분에서 "2D", "3D", "스크립트", "Game" 및 "AssetLib" 버튼 옆에 나타나는 새 UI를 생성할 수 있습니다. 이러한 편집기 플러그인을 "메인 화면 플러그인"이라고 합니다.

이 튜토리얼에서는 기본 메인 화면 플러그인을 생성하는 과정을 안내합니다. 단순화를 위해 기본 화면 플러그인에는 콘솔에 텍스트를 인쇄하는 단일 버튼이 포함됩니다.

플러그인 초기화

먼저 플러그인 메뉴에서 새 플러그인을 만듭니다. 이 튜토리얼에서는 main_screen라는 폴더에 넣지만 원하는 이름을 사용할 수 있습니다.

The plugin script will come with _enter_tree() and _exit_tree() methods, but for a main screen plugin we need to add a few extra methods. Add four extra methods such that the script looks like this:

@tool
extends EditorPlugin


func _enter_tree():
    pass


func _exit_tree():
    pass


func _has_main_screen():
    return true


func _make_visible(visible):
    pass


func _get_plugin_name():
    return "Main Screen Plugin"


func _get_plugin_icon():
    return EditorInterface.get_editor_theme().get_icon("Node", "EditorIcons")

The important part in this script is the _has_main_screen() function, which is overridden to return true. This function is automatically called by the editor on plugin activation, to tell it that this plugin adds a new center view to the editor. For now, we'll leave this script as-is and we'll come back to it later.

메인 씬

만들기는 Control에서 파생된 루트 노드가 있는 새로운 씬입니다(이 예제 플러그인의 경우 루트 노드를 CenterContainer로 만듭니다). 이 루트 노드를 선택하고, 뷰포트에서 Layout 메뉴를 클릭하고 Full Rect를 선택합니다. 또한 검사기에서 Expand 수직 크기 플래그를 활성화해야 합니다. 이제 패널은 기본 뷰포트에서 사용 가능한 모든 공간을 사용합니다.

다음으로, 예제 메인 화면 플러그인에 버튼을 추가해 보겠습니다. Button 노드를 추가하고 텍스트를 "Print Hello" 또는 이와 유사한 것으로 설정합니다. 다음과 같이 버튼에 스크립트를 추가합니다.

@tool
extends Button


func _on_print_hello_pressed():
    print("Hello from the main screen plugin!")

그런 다음 "누른"시그널를 자체에 연결하십시오. 시그널와 관련하여 도움이 필요하면 시그널 사용하기 문서를 참조하세요.

메인 화면 패널이 끝났습니다. 씬을 main_panel.tscn로 저장합니다.

플러그인 스크립트 업데이트

We need to update the main_screen_plugin.gd script so the plugin instantiates our main panel scene and places it where it needs to be. Here is the full plugin script:

@tool
extends EditorPlugin


const MainPanel = preload("res://addons/main_screen/main_panel.tscn")

var main_panel_instance


func _enter_tree():
    main_panel_instance = MainPanel.instantiate()
    # Add the main panel to the editor's main viewport.
    EditorInterface.get_editor_main_screen().add_child(main_panel_instance)
    # Hide the main panel. Very much required.
    _make_visible(false)


func _exit_tree():
    if main_panel_instance:
        main_panel_instance.queue_free()


func _has_main_screen():
    return true


func _make_visible(visible):
    if main_panel_instance:
        main_panel_instance.visible = visible


func _get_plugin_name():
    return "Main Screen Plugin"


func _get_plugin_icon():
    # Must return some kind of Texture for the icon.
    return EditorInterface.get_editor_theme().get_icon("Node", "EditorIcons")

A couple of specific lines were added. MainPanel is a constant that holds a reference to the scene, and we instantiate it into main_panel_instance.

The _enter_tree() function is called before _ready(). This is where we instantiate the main panel scene, and add them as children of specific parts of the editor. We use EditorInterface.get_editor_main_screen() to obtain the main editor screen and add our main panel instance as a child to it. We call the _make_visible(false) function to hide the main panel so it doesn't compete for space when first activating the plugin.

플러그인이 비활성화되면 _exit_tree() 함수가 호출됩니다. 기본 화면이 여전히 존재하는 경우 queue_free()를 호출하여 인스턴스를 해제하고 메모리에서 제거합니다.

필요에 따라 기본 패널을 숨기거나 표시하도록 _make_visible() 기능이 재정의되었습니다. 이 함수는 사용자가 편집기 상단의 기본 뷰포트 버튼을 클릭하면 편집기에 의해 자동으로 호출됩니다.

_get_plugin_name() 및 _get_plugin_icon() 기능은 플러그인의 기본 뷰포트 버튼에 대해 표시되는 이름과 아이콘을 제어합니다.

Another function you can add is the _handles() function, which allows you to handle a node type, automatically focusing the main screen when the type is selected. This is similar to how clicking on a 3D node will automatically switch to the 3D viewport.

Main screen icons

You can either use one of the built-in icons from the editor, or provide your own icon for the main screen plugin. In both cases, this is done by overriding the _get_plugin_icon() method in the plugin script.

To use a built-in icon, copy an icon name from the Godot editor icons website. Use the name copied from the website as the first parameter of EditorInterface.get_editor_theme().get_icon() (the second parameter should remain "EditorIcons").

You can use a custom icon by returning something such as preload("res://addons/main_screen/icon.svg"). When designing your own icon, you should follow the same guidelines as for node icons (SVG format recommended, 16×16 size). See 편집기 for information on how to create icons for your plugin.

플러그인을 사용해 보세요

프로젝트 설정에서 플러그인을 활성화합니다. 메인 뷰포트 위의 2D, 3D, 스크립트 옆에 새로운 버튼이 있는 것을 볼 수 있습니다. 이를 클릭하면 새로운 메인 화면 플러그인으로 이동하고 가운데 버튼을 누르면 텍스트가 인쇄됩니다.

이 플러그인의 완성된 버전을 사용해보고 싶다면 여기에서 플러그인 데모를 확인하세요: https://github.com/godotengine/godot-demo-projects/tree/master/plugins

메인 화면 플러그인의 기능에 대한 더 완전한 예를 보려면 여기에서 2.5D 데모 프로젝트를 확인하세요: https://github.com/godotengine/godot-demo-projects/tree/master/misc/2.5d