一键导入
godot-create-plugin
用于创建带有自定义面板、停靠栏和工具的 Godot 编辑器插件。生成 plugin.cfg 配置、 EditorPlugin 脚本模板、自定义编辑器 UI 组件,并集成 ProjectSettings。按照 Godot 4.x 最佳实践创建完整的插件结构。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
用于创建带有自定义面板、停靠栏和工具的 Godot 编辑器插件。生成 plugin.cfg 配置、 EditorPlugin 脚本模板、自定义编辑器 UI 组件,并集成 ProjectSettings。按照 Godot 4.x 最佳实践创建完整的插件结构。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
当 Godot 代码中存在通过 get_node()、get_parent() 或直接引用产生的紧耦合依赖时使用。 检测耦合模式并将其转换为基于 Signal 的通信方式。组件变得独立、可测试且可复用。 在改进架构的同时精确保留原有行为。
当 Godot 代码中存在相互冲突的操作导致未定义行为时使用。检测同一属性在多处设置 (_ready、_process、代码+编辑器)、同一 Signal 多次连接、冲突的物理模式、 竞争的动画等问题。自动通过明确的所有权归属解决冲突。
当 Godot 代码中存在硬编码的游戏数据(如 const 数组、字典或内嵌值)时使用。检测内联数据 如敌人属性、物品定义、关卡配置等。自动提取为 .tres Resource 文件,使数据在编辑器中 可见、易于修改,并支持数据驱动的设计。
当构建 Godot 功能时,代码使用 .new() 创建节点而非使用场景时触发。 检测 Timer.new()、Area2D.new()、Sprite2D.new() 等代码创建的对象。 自动生成 .tscn 场景文件,更新父脚本使用 @onready 引用,并创建可复用的组件库。
当 Godot 项目在编辑器(.tscn)和代码(.gd)之间存在位置冲突、相机跟随背景、 或运行时位置与编辑器预览不匹配时使用。编排所有 3 个位置同步子技能: sync-static-positions、sync-camera-positions 和 sync-parallax。 每个操作针对特定的位置冲突类型。
在开发 Godot 游戏时需要为 GDScript 类、Signal、场景初始化和集成流程提供全面的测试覆盖时使用。 生成 GUT 框架单元测试、集成测试、Mock/Stub 辅助工具和 CI/CD 测试运行器配置。
| name | godot-create-plugin |
| version | 3.0.0 |
| displayName | 创建 Godot 编辑器插件 |
| description | 用于创建带有自定义面板、停靠栏和工具的 Godot 编辑器插件。生成 plugin.cfg 配置、 EditorPlugin 脚本模板、自定义编辑器 UI 组件,并集成 ProjectSettings。按照 Godot 4.x 最佳实践创建完整的插件结构。 |
| author | Asreonn |
| license | MIT |
| category | game-development |
| type | tool |
| difficulty | intermediate |
| audience | ["developers"] |
| keywords | ["godot","editor-plugin","plugin.cfg","EditorPlugin","custom-dock","editor-panel","tool-script","gdscript","project-settings","editor-extension"] |
| platforms | ["macos","linux","windows"] |
| repository | https://github.com/asreonn/godot-superpowers |
| homepage | https://github.com/asreonn/godot-superpowers#readme |
| permissions | {"filesystem":{"read":[".gd",".tscn","project.godot"],"write":[".cfg",".gd",".tscn","project.godot"]},"git":true} |
| behavior | {"auto_rollback":true,"validation":true,"git_commits":true} |
| outputs | 完整的插件结构,包含 plugin.cfg、EditorPlugin 脚本、自定义停靠栏/面板以及设置集成 |
| requirements | Godot 4.x 项目, Git 仓库 |
| execution | 使用模板生成插件文件并进行 git 提交 |
| integration | 可与 godot-refactor 编排器配合使用,创建可复用的编辑器工具 |
扩展编辑器,而不是对抗它。 Godot 编辑器插件让你可以直接在编辑器界面中添加自定义工具、面板和工作流。
创建完整的 Godot 编辑器插件:
addons/my_plugin/
├── plugin.cfg # Plugin metadata
├── my_plugin.gd # EditorPlugin entry point
├── docks/
│ ├── main_dock.gd # Custom side dock logic
│ ├── main_dock.tscn # Dock UI scene
│ └── bottom_panel.gd # Bottom panel logic
├── ui/
│ ├── inspector_plugin.gd # Custom inspector controls
│ └── property_editor.gd # Custom property editors
└── tools/
├── scene_tool.gd # @tool script for editor functionality
└── asset_processor.gd # Import/Process automation
创建关卡编辑器、地形工具或集成到 Godot 中的专用工作流。
为自定义 Resource 或 Node 添加自定义属性编辑器。
自动化导入工作流、批量处理或自定义导出器。
跨场景操作、管理资源或提供项目洞察的工具。
_enter_tree() 和 _exit_tree()生成文件:addons/my_dock/plugin.cfg
[plugin]
name="My Custom Dock"
description="Adds a custom dock panel to the editor"
author="Your Name"
version="1.0.0"
script="my_dock.gd"
生成文件:addons/my_dock/my_dock.gd
@tool
extends EditorPlugin
const DOCK_SCENE = preload("res://addons/my_dock/dock.tscn")
var dock_instance: Control
func _enter_tree():
# Add custom dock to left slot
dock_instance = DOCK_SCENE.instantiate()
add_control_to_dock(DOCK_SLOT_LEFT_BR, dock_instance)
# Add custom settings
_setup_project_settings()
func _exit_tree():
# Remove dock when plugin is disabled
if dock_instance:
remove_control_from_docks(dock_instance)
dock_instance.queue_free()
func _setup_project_settings():
# Add custom project settings for plugin configuration
if not ProjectSettings.has_setting("my_plugin/enabled_features"):
ProjectSettings.set_setting("my_plugin/enabled_features", ["feature_a", "feature_b"])
ProjectSettings.add_property_info({
"name": "my_plugin/enabled_features",
"type": TYPE_ARRAY,
"hint": PROPERTY_HINT_TYPE_STRING,
"hint_string": "24/17:Feature"
})
生成文件:addons/my_dock/dock.gd
@tool
extends Control
@onready var button: Button = $VBoxContainer/Button
@onready var label: Label = $VBoxContainer/Label
func _ready():
button.pressed.connect(_on_button_pressed)
func _on_button_pressed():
label.text = "Button clicked at %s" % Time.get_time_string_from_system()
# Access plugin settings
var features = ProjectSettings.get_setting("my_plugin/enabled_features", [])
print("Enabled features: ", features)
生成文件:addons/my_dock/dock.tscn
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://addons/my_dock/dock.gd" id="1_script"]
[node name="MyDock" type="Control"]
layout_mode = 3
anchors_preset = 15
script = ExtResource("1_script")
[node name="VBoxContainer" type="VBoxContainer" parent="."]
layout_mode = 1
anchors_preset = 15
[node name="Button" type="Button" parent="VBoxContainer"]
text = "Click Me"
[node name="Label" type="Label" parent="VBoxContainer"]
text = "Ready"
生成文件:addons/inspector_plugin/plugin.cfg
[plugin]
name="Custom Inspector"
description="Adds custom property editors"
author="Your Name"
version="1.0.0"
script="custom_inspector.gd"
生成文件:addons/inspector_plugin/custom_inspector.gd
@tool
extends EditorPlugin
var inspector_plugin: EditorInspectorPlugin
func _enter_tree():
inspector_plugin = preload("res://addons/inspector_plugin/my_inspector_plugin.gd").new()
add_inspector_plugin(inspector_plugin)
func _exit_tree():
remove_inspector_plugin(inspector_plugin)
生成文件:addons/inspector_plugin/my_inspector_plugin.gd
@tool
extends EditorInspectorPlugin
func _can_handle(object: Object) -> bool:
# Apply to any node with custom script
return object is Node
func _parse_property(object: Object, type: Variant.Type, name: String,
hint_type: PropertyHint, hint_string: String,
usage_flags: int, wide: bool) -> bool:
# Handle specific property types
if name == "my_custom_property":
add_property_editor(name, preload("res://addons/inspector_plugin/custom_property_editor.gd").new())
return true # Handled
return false # Use default editor
生成文件:addons/tools/scene_batch_processor.gd
@tool
extends EditorScript
## Batch process scenes in editor
## Run via: Editor > Run > Run Script
@export var target_directory: String = "res://scenes"
@export var operation: String = "cleanup"
func _run():
print("Starting batch processing...")
var dir = DirAccess.open(target_directory)
if dir:
dir.list_dir_begin()
var file_name = dir.get_next()
while file_name != "":
if file_name.ends_with(".tscn"):
_process_scene(target_directory.path_join(file_name))
file_name = dir.get_next()
print("Batch processing complete!")
func _process_scene(path: String):
var scene = load(path)
if scene:
print("Processing: ", path)
# Perform operations on packed scene
| 位置 | 说明 | 适用场景 |
|---|---|---|
DOCK_SLOT_LEFT_UL | 左侧,左上 | 主要工具,频繁访问 |
DOCK_SLOT_LEFT_BL | 左侧,左下 | 次要面板 |
DOCK_SLOT_LEFT_UR | 左侧,右上 | 检查器辅助 |
DOCK_SLOT_LEFT_BR | 左侧,右下 | 调试/信息面板 |
DOCK_SLOT_RIGHT_UL | 右侧,左上 | 属性、设置 |
DOCK_SLOT_RIGHT_BL | 右侧,左下 | 控制台、输出 |
DOCK_SLOT_RIGHT_UR | 右侧,右上 | 低频工具 |
DOCK_SLOT_RIGHT_BR | 右侧,右下 | 底部辅助 |
func _enter_tree():
# Called when plugin is enabled
# Add docks, menus, inspectors here
pass
func _exit_tree():
# Called when plugin is disabled
# Clean up everything added in _enter_tree
pass
func _has_main_screen() -> bool:
# Return true if plugin provides main screen (like 2D/3D/Script)
return false
func _make_visible(visible: bool):
# Called when main screen tab is selected/deselected
pass
func _get_plugin_name() -> String:
# Name shown in main screen tabs
return "My Plugin"
func _get_plugin_icon() -> Texture2D:
# Icon for main screen tab
return get_editor_interface().get_base_control().get_theme_icon("Node", "EditorIcons")
添加自定义 ProjectSettings 条目:
func _enter_tree():
# Add setting if it doesn't exist
if not ProjectSettings.has_setting("my_plugin/enable_debug"):
ProjectSettings.set_setting("my_plugin/enable_debug", false)
# Define property metadata
ProjectSettings.add_property_info({
"name": "my_plugin/enable_debug",
"type": TYPE_BOOL,
"hint": PROPERTY_HINT_NONE
})
# Set as basic setting (shows in Project Settings UI)
ProjectSettings.set_initial_value("my_plugin/enable_debug", false)
ProjectSettings.set_as_basic("my_plugin/enable_debug", true)
# Get the editor interface
var interface = get_editor_interface()
# Access editor features
var editor_selection = interface.get_selection()
var editor_settings = interface.get_editor_settings()
var resource_preview = interface.get_resource_previewer()
# Get current scene
var edited_scene_root = interface.get_edited_scene_root()
# Get selected nodes
var selected_nodes = editor_selection.get_selected_nodes()
# Open scene in editor
interface.open_scene_from_path("res://scene.tscn")
# Reload scene
interface.reload_scene_from_path("res://scene.tscn")
# Play scene
interface.play_current_scene()
addons/plugin_name/ 中的完整插件结构可与以下技能配合使用:
_exit_tree() 中正确清理以下情况不需要创建插件:
_exit_tree() 中清理 - 移除所有添加的 UI/组件@tool 脚本 - 使代码能在编辑器中运行Engine.is_editor_hint() - 区分编辑器和运行时plugin_name/setting_name 命名约定ProjectSettings.save()