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.
Checking the stable version of the documentation...
간단한 플러그인 만들기
이 튜토리얼에서 다루는 내용
메인 화면 플러그인을 사용하면 편집기 중앙 부분에서 "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")
#if TOOLS
using Godot;
[Tool]
public partial class MainScreenPlugin : EditorPlugin
{
public override void _EnterTree()
{
}
public override void _ExitTree()
{
}
public override bool _HasMainScreen()
{
return true;
}
public override void _MakeVisible(bool visible)
{
}
public override string _GetPluginName()
{
return "Main Screen Plugin";
}
public override Texture2D _GetPluginIcon()
{
return EditorInterface.Singleton.GetEditorTheme().GetIcon("Node", "EditorIcons");
}
}
#endif
이 스크립트에서 중요한 부분은 _has_main_screen() 함수인데, 이 함수는 오버로드되어 ``true``를 반환합니다. 이 함수는 플러그인 활성화 시 편집기에 의해 자동으로 호출되어 이 플러그인이 편집기에 새로운 중앙 보기를 추가한다는 것을 알려줍니다. 지금은 이 스크립트를 그대로 두고 나중에 다시 설명하겠습니다.
메인 씬
만들기는 Control``에서 파생된 루트 노드가 있는 새로운 씬입니다(이 예제 플러그인의 경우 루트 노드를 ``CenterContainer``로 만듭니다). 이 루트 노드를 선택하고, 뷰포트에서 ``Layout 메뉴를 클릭하고 Full Rect``를 선택합니다. 또한 검사기에서 ``Expand 수직 크기 플래그를 활성화해야 합니다. 이제 패널은 기본 뷰포트에서 사용 가능한 모든 공간을 사용합니다.
다음으로, 예제 메인 화면 플러그인에 버튼을 추가해 보겠습니다. Button 노드를 추가하고 텍스트를 "Print Hello" 또는 이와 유사한 것으로 설정합니다. 다음과 같이 버튼에 스크립트를 추가합니다.
@tool
extends Button
func _on_print_hello_pressed():
print("Hello from the main screen plugin!")
using Godot;
[Tool]
public partial class PrintHello : Button
{
private void OnPrintHelloPressed()
{
GD.Print("Hello from the main screen plugin!");
}
}
그런 다음 "누른"시그널를 자체에 연결하십시오. 시그널와 관련하여 도움이 필요하면 시그널 사용하기 문서를 참조하세요.
메인 화면 패널이 끝났습니다. 씬을 ``main_panel.tscn``로 저장합니다.
플러그인 스크립트 업데이트
플러그인이 메인 패널 씬을 인스턴스화하고 필요한 위치에 배치할 수 있도록 main_screen_plugin.gd 스크립트를 업데이트해야 합니다. 전체 플러그인 스크립트는 다음과 같습니다.
@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")
#if TOOLS
using Godot;
[Tool]
public partial class MainScreenPlugin : EditorPlugin
{
PackedScene MainPanel = ResourceLoader.Load<PackedScene>("res://addons/main_screen/main_panel.tscn");
Control MainPanelInstance;
public override void _EnterTree()
{
MainPanelInstance = (Control)MainPanel.Instantiate();
// Add the main panel to the editor's main viewport.
EditorInterface.Singleton.GetEditorMainScreen().AddChild(MainPanelInstance);
// Hide the main panel. Very much required.
_MakeVisible(false);
}
public override void _ExitTree()
{
if (MainPanelInstance != null)
{
MainPanelInstance.QueueFree();
}
}
public override bool _HasMainScreen()
{
return true;
}
public override void _MakeVisible(bool visible)
{
if (MainPanelInstance != null)
{
MainPanelInstance.Visible = visible;
}
}
public override string _GetPluginName()
{
return "Main Screen Plugin";
}
public override Texture2D _GetPluginIcon()
{
// Must return some kind of Texture for the icon.
return EditorInterface.Singleton.GetEditorTheme().GetIcon("Node", "EditorIcons");
}
}
#endif
몇 가지 특정 라인이 추가되었습니다. ``MainPanel``는 씬에 대한 참조를 보유하는 상수이며 이를 `main_panel_instance`에 인스턴스화합니다.
_enter_tree() 함수는 _ready() 이전에 호출됩니다. 여기에서 메인 패널 씬을 인스턴스화하고 이를 편집기의 특정 부분의 자식 노드로 추가합니다. EditorInterface.get_editor_main_screen()``를 사용하여 메인 편집기 화면을 얻고 메인 패널 인스턴스를 하위 항목으로 추가합니다. 플러그인을 처음 활성화할 때 공간을 두고 경쟁하지 않도록 메인 패널을 숨기기 위해 ``_make_visible(false) 함수를 호출합니다.
플러그인이 비활성화되면 _exit_tree() 함수가 호출됩니다. 기본 화면이 여전히 존재하는 경우 ``queue_free()``를 호출하여 인스턴스를 해제하고 메모리에서 제거합니다.
필요에 따라 기본 패널을 숨기거나 표시하도록 _make_visible() 기능이 재정의되었습니다. 이 함수는 사용자가 편집기 상단의 기본 뷰포트 버튼을 클릭하면 편집기에 의해 자동으로 호출됩니다.
_get_plugin_name() 및 _get_plugin_icon() 기능은 플러그인의 기본 뷰포트 버튼에 대해 표시되는 이름과 아이콘을 제어합니다.
추가할 수 있는 또 다른 기능은 handles() 기능입니다. 이 기능을 사용하면 노드 유형을 처리할 수 있으며 유형을 선택하면 자동으로 메인 화면에 초점을 맞출 수 있습니다. 이는 3D 노드를 클릭하면 자동으로 3D 뷰포트로 전환되는 방식과 유사합니다.
플러그인을 사용해 보세요
프로젝트 설정에서 플러그인을 활성화합니다. 메인 뷰포트 위의 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