创建插件

项目 -> 项目设置 -> 插件 -> 创建插件

插件名: MyTools

语言: C#

脚本名: 默认为插件名.cs (MyTools.cs)

插件脚本

插件中涉及的脚本均建议使用if宏包裹

PLAINTEXT
#if TOOLS

// Code...

#endif

插件中的部分类脚本需要添加[Tool]标签,如Control、EditorPlugin等

CS
[Tool]
public partial class MyToolsUI : Control {
	// Code...
}

插件主脚本 (MyTools.cs)

CS
#if TOOLS
using Godot;

[Tool]
public partial class MyTools : EditorPlugin
{
    Control control;
    public override void _EnterTree()
    {
	    // 实例化组件(自行创建一个Control场景 或 代码创建)
        control = GD.Load<PackedScene>("res://addons/MyTools/MyTools.tscn").Instantiate<Control>();
        // 添加组件到侧边栏
        AddControlToDock(DockSlot.RightUl, control);
        // AddControlToBottomPanel
        // AddControlToContainer
    }

    public override void _ExitTree()
    {
	    // 删除组件
        RemoveControlFromDocks(control);
    }
}

#endif

获取当前编辑的场景

CS
Node root = GetTree().EditedSceneRoot;

: Cheyne Xie

: https://chaim.eu.org/posts/4f0f6a41/

: CC BY-NC-SA 4.0

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Please attribute the source, use non-commercially, and maintain the same license.