Communitygithub.com

taconotsandwich/unity-agentic-tools

一個用於讀取和編輯 Unity 場景、預製物件及資源的 CLI 工具,其設計以極簡 token 使用為導向,並在運行的 Unity Editor 之間運作。

unity-agentic-tools 是什麼?

Unity Agentic Tools 是一個命令列介面(CLI),專為 AI 代理程式設計,使其能與 Unity Editor 進行高效率、低 token 消耗的互動。它提供一個橋接層,讓代理程式可以列出並執行 Unity 場景中的指令、查詢場景層級、修改物件屬性,以及執行專案特定的可編寫腳本自動化任務。此工具支援多種平台,包括 Claude Code、Coda 和 Cursor,並且可以透過 WebSocket 串流即時的 Editor 事件。其主要優勢在於避免直接操作 Unity 的二進位或序列化檔案(如 `.unity` 或 `.prefab`),而是透過 CLI 執行指令,這不僅更安全,也更符合 token 使用效率。使用者可以透過 `list` 來探索可用指令,並使用 `run` 來執行它們,或使用 `stream` 來監控即時事件。它也支援透過 `[AgenticCommand]` 屬性來擴展自訂的專案指令。

相容平台~Claude Code~Codex CLI~Cursor✓Antigravity
npx skills add taconotsandwich/unity-agentic-tools

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Unity Agentic Tools

使用此技能進行 Unity Agentic Tools CLI 的安裝設定、指令探索、指令執行、即時 Editor 橋接工作流程,以及高階專案自動化。

關鍵:對於 Unity 操作,請使用 CLI 指令執行器。除非使用者明確要求處理原始檔案,否則請勿手動修改 Unity 序列化檔案(.unity、.prefab、.asset、.mat、.anim、.controller、.meta、ProjectSettings/)。

指令列表

指令功能說明
list [query]探索內建別名、帶有屬性的專案指令,以及可選的原始靜態 API。--brief 會省略每個參數的詳細資訊;--raw 則會加入原始靜態方法。
run <target> [args...]透過 Unity 橋接器執行指令別名或原始的公開靜態 C# 方法/屬性。
stream [topic]透過 WebSocket 觀看即時橋接器事件。
install安裝 Unity 橋接器套件。
uninstall移除 Unity 橋接器套件。
cleanup移除過時的橋接器狀態或可重建的 .unity-agentic 快取。
status檢查指令執行器和橋接器的可連線性,以及一個 readiness 區塊,顯示 Editor 正在忙於處理什麼。

指令預設輸出緊湊的單行 JSON;傳遞 --pretty 參數以獲得縮排輸出。進行探索時,建議使用 list <query> --brief。

預設情況下,install 會寫入 GitHub 套件網址。若要進行本地橋接器套件開發,請使用 install --local [path];除非傳遞 install --remote,否則現有的 file: 依賴項將會被保留。

預設工作流程

  1. unity-agentic-tools status -p <project>
  2. unity-agentic-tools list <query> --brief -p <project>
  3. 使用 query.*、scene.hierarchy、ui.snapshot 或螢幕截圖檢查當前狀態。
  4. unity-agentic-tools run <target> ... -p <project>
  5. 使用對應的查詢、快照、螢幕截圖、測試或控制台串流進行驗證。

範例

unity-agentic-tools list scene --brief -p <project>
unity-agentic-tools run project.refresh -p <project>
unity-agentic-tools run query.scene Assets/Scenes/Main.unity -p <project>
unity-agentic-tools run create.gameobject Assets/Scenes/Main.unity EnemyRoot Gameplay -p <project>
unity-agentic-tools run update.transform Assets/Scenes/Main.unity Player 1,2,3 0,90,0 1,1,1 -p <project>
unity-agentic-tools stream console --type Error -p <project>
unity-agentic-tools cleanup --cache -p <project>

使用單引號以位置參數的形式傳遞結構化參數——CLI 會自行編碼外層的 JSON 陣列,因此無需進行跳脫。對於以 - 開頭的參數,請保留 --args '<json array>'。請參閱 reference/troubleshooting.md 中的「JSON Args」。

unity-agentic-tools run update.batch Assets/Scenes/Main.unity '[{"gameObjectPath":"Player","propertyPath":"m_Name","value":"Hero"}]' -p <project>

當不存在別名或 [AgenticCommand] 包裝器時,可以直接呼叫原始的公開靜態 API。

unity-agentic-tools run UnityEditor.AssetDatabase.Refresh -p <project>
unity-agentic-tools run UnityEditor.EditorApplication.ExecuteMenuItem "File/Save" -p <project>

專案指令

請勿為每個 Unity 操作新增一個 CLI 指令。若要暴露專案特定的行為,請在 Unity Editor C# 中將 [AgenticCommand] 屬性新增至公開靜態方法/屬性:

using UnityAgenticTools.Commands;

public static class BuildCommands
{
    [AgenticCommand("build.addressables", "Build Addressables content.")]
    public static object BuildAddressables(string profile)
    {
        return new { success = true, profile };
    }
}

然後使用:

unity-agentic-tools list build --brief -p <project>
unity-agentic-tools run build.addressables Production -p <project>

參考資料

  • reference/live-editor-workflows.md:即時 Editor 設定、修改、UI 以及批次工作流程
  • reference/command-reference.md:生成的別名參考,包含參數提示(<required> [optional])
  • reference/troubleshooting.md:橋接器、超時、參考、JSON 參數以及驗證

故障排除

完整細節請參閱 reference/troubleshooting.md。快速提示:

  • 橋接器無法連線:請參閱「橋接器無法連線」(安裝、開啟 Unity、等待編譯、檢查狀態、清理)。reachable: true 但 is_stable: false 表示忙碌中,並非故障。
  • 長時間建置超時:run 預設超時時間為 60 秒;請參閱「長時間執行的指令」(--timeout 1200000、--no-wait)。
  • 在 play.enter 之後 Play 模式看起來不對:回應報告的是當前狀態,而非請求的狀態。請輪詢 play.state;請參閱 reference/live-editor-workflows.md 中的「Play 模式轉換」。
  • 在轉換期間讀取速度慢:這是預期行為。讀取操作會等待領域重新載入最多 30 秒,而不是直接失敗;請參閱「長時間執行指令」中的「領域重新載入」。
  • 過時的 @hN/@uN 參考:重新執行 scene.hierarchy 或 ui.snapshot;請參閱「過時的參考」。
  • 需要控制台日誌:unity-agentic-tools stream console --duration 5000 -p <project>。
  • 需要原始 API:unity-agentic-tools list <type-or-namespace> --raw -p <project>。

相關技能