Prefab Text Exporter

SkillDev tools

Design guide for the Unity Prefab text export tool. Use this skill when you need to: (1) understand or modify PrefabToTextExporter-related code, (2) extend export formats or add supported types, (3) add Component type mappings, or (4) adjust filtering logic or output formats.

Available today. Use it from your connected AI after setup.

Add ahel to your AI once: Claude, ChatGPT, Cursor, Claude Code or Codex. Then ask it to use this.

Then ask your AI: use the Prefab Text Exporter skill

What this skill tells your AI

The instructions your AI receives, as published by red-candle-games-co-ltd/monofsm in skills/prefab-text-exporter/SKILL.md and read by ahel’s review.

將 Unity Prefab 轉換為 Godot .tscn 風格的純文字格式,方便 LLM 閱讀理解場景結構。

設計理念

  • 單向輸出:只匯出文字,不需要反向轉換回 Prefab
  • LLM 友善:輸出格式易於理解,包含階層結構和欄位資訊
  • 篩選機制:可排除預設值、指定 Component 類型、排除特定欄位

檔案結構

MonoFSM/1_MonoFSM_Core/Editor/PrefabExporter/
├── UnityTypeFormatter.cs      # 類型格式化(Vector, Color, Object Reference 等)
├── PrefabExportSettings.cs    # 設定資料結構 + EditorPrefs 持久化
├── PrefabToTextExporter.cs    # 核心轉換邏輯(遍歷 GameObject、比較預設值)
├── PrefabToTextContextMenu.cs # 右鍵選單(Assets/MonoFSM/複製 Prefab 為文字)
└── PrefabToTextWindow.cs      # OdinEditorWindow 進階視窗

輸出格式

[gd_scene format=3 uid="unity_prefab"]

[node name="Player" type="RigidBody3D"]
position = Vector3(0, 1, 0)
# Component: Rigidbody
mass = 10

[node name="Arm" type="MeshInstance3D" parent="."]
position = Vector3(0.5, 0, 0)
# Component: MeshRenderer
material = ExtResource("Assets/Materials/Mat.mat")

[node name="Hand" type="Node3D" parent="Arm"]
scale = Vector3(0.5, 0.5, 0.5)

類型格式化規則 (UnityTypeFormatter)

Unity 類型輸出格式
Vector3Vector3(x, y, z)
QuaternionVector3(euler.x, euler.y, euler.z)
ColorColor(r, g, b, a)
Asset ReferenceExtResource("Assets/path/to/file.ext")
Scene ObjectNodePath("Parent/Child")
Enum"EnumValueName"
Array[item1, item2, ...]

新增類型支援

在 FormatValue() 的 switch expression 中新增:

return value switch
{
    // 新增自訂類型
    MyCustomType custom => $"Custom({custom.field1}, {custom.field2})",
    // ... existing cases
};

節點類型對應 (DetermineNodeType)

根據 GameObject 上的 Component 決定 Godot 節點類型:

Unity ComponentGodot Type
CameraCamera3D
RigidbodyRigidBody3D
CharacterControllerCharacterBody3D
MeshRendererMeshInstance3D
ColliderCollisionShape3D
AnimatorAnimationPlayer
CanvasCanvasLayer
(default)Node3D

新增對應

在 PrefabToTextExporter.DetermineNodeType() 中新增:

if (go.GetComponent<MyComponent>()) return "MyGodotType";

預設值比較機制

使用臨時 GameObject 建立 Component 預設實例,快取預設值後比較:

// 快取結構
Dictionary<Type, Dictionary<string, object>> _defaultCache

// 比較流程
1. GetDefaultValues(componentType) - 取得或建立預設值快取
2. IsDefaultValue(property, defaults) - 比較當前值與預設值
3. 若相同則跳過輸出

使用方式

右鍵快速複製

Project 視窗選擇 Prefab → 右鍵 → MonoFSM/複製 Prefab 為文字

進階視窗

Tools → MonoFSM → Prefab Text Exporter

  • 可調整 Component 篩選
  • 可設定欄位排除規則
  • 即時預覽輸出結果
  • 設定自動儲存到 EditorPrefs

常見擴充需求

新增排除欄位

在 PrefabExportSettings._excludedFieldNames 中加入欄位名稱。

自訂輸出格式

修改 PrefabToTextExporter.TraverseGameObject() 中的 StringBuilder 輸出。

支援新的 SerializedPropertyType

在 UnityTypeFormatter.FormatPropertyValue() 的 switch 中新增 case。

Signals

GitHub stars
25
Forks
2
Last commit
Sep 2026
Advanced
Item type
skill
Key
prefab-text-exporter
Source
github.com/red-candle-games-co-ltd/monofsm