t1k:unity:ui:figma-export
| Field | Value |
|---|---|
| Module | ui |
| Version | 3.43.4 |
| Effort | high |
| Tools | — |
Keywords: chrome, designer handoff, export, figma, layers, plugin api, popup to figma, prefab to figma, reskin, sprites, tmp, ugui to figma, unity ui to figma
How to invoke
Section titled “How to invoke”/t1k:unity:ui:figma-export<figma file url + page> <prefab dir> <Prefab1,Prefab2,...> [feature label]Unity uGUI → Figma (layered, no token)
Section titled “Unity uGUI → Figma (layered, no token)”The reverse direction (Figma → Unity) is t1k-unity-ui-figma-import.
Why no token: the Figma REST API cannot write nodes, and the Figma MCP use_figma tool runs out of calls on the Starter plan after roughly one feature. This skill uses the figma Plugin-API global on the user’s own logged-in Figma tab, driven by Claude in Chrome. Nothing is stored, and the user’s session is the only credential.
What the designer gets (per feature, on the chosen page)
Section titled “What the designer gets (per feature, on the chosen page)”| Section | Content |
|---|---|
<Label> - Unity render (reference) | One flat 1080×1920 Unity render per prefab |
<Label> - Layers (Unity hierarchy) | One frame per prefab. Child frames carry the GameObject names. A leaf Image is an instance named after its GameObject. A container’s own image is [Image] <sprite>, its text is [Text], and Spine/particles are [Spine] / [FX] image slots. [fx: kind] marks particle frames. |
_Sprites - <Label> (reskin here) | One component sprite/<name> per sprite, holding the Unity asset path, native size, 9-slice border, the GameObjects that use it, and key:. Swapping a component’s image reskins every use. |
Pipeline
Section titled “Pipeline”Unity prefab ──UiFigmaExport.cs (headless, worktree)──▶ export/*.json + sprites/*.png + render_*.png ──gen.py──▶ sprites.js · slice.js · ref.js · build_<Prefab>.js ──Claude in Chrome: file_upload + t1kRun──▶ Figma pageAll scripts are in scripts/. Pick a scratch dir $X (the session scratchpad).
1. Export from Unity (headless, never the user’s open Editor)
Section titled “1. Export from Unity (headless, never the user’s open Editor)”The C# runs in a project with no Editor open on it, so use a git worktree of the repo (t1k-worktree; submodules initialised, Library/ warm or ~10 min first import). Never launch Unity on a project the user has open (unity-forbidden-operations.md).
T1K_UNITY_RAW_LAUNCH_OK=1 bash .claude/skills/t1k-unity-ui-figma-export/scripts/run-export.sh \ <worktree>/<UnityProject> $X/export <Assets/.../Prefabs> Prefab1,Prefab2- A prefab name is a file name under
<Assets/.../Prefabs>, or a full project path ending in.prefab(e.g.Assets/Foo/Bar/Baz.prefab) for prefabs spread over several folders; the output files are named after the file name without the extension. A root that is not a stretch root (a bottom nav bar, a HUD strip) keeps its own rect instead of being stretched to 1080×1920. - Copies
scripts/editor/*.csintoAssets/Editor/_UiFigmaExport/, runsUiFigmaExport.Run, and deletes them again on exit. It also bridges the Unity Hub licensing socket (Flatpak Hub). - Uses the t1k batch gate when
.claude/scripts/unity-batch-gate.shexists. Otherwise it launches raw, which the PreToolUse unity guard only allows with theT1K_UNITY_RAW_LAUNCH_OK=1prefix. UIFX_ROOT_UI= the runtime root-canvas prefab whose CanvasScaler is copied (defaultPackages/com.gdk.core/Prefabs/CommonUIPrefab/RootUI.prefab, the gdk core root canvas; setUIFX_ROOT_UIto another path when the project ships its own root). The canvas must come out 1080×1920.- Output:
<Prefab>.json(full hierarchy: rects, anchors, Image/TMP/Mask/UIGradient/Spine/fx),sprites/+index.json,render_<Prefab>.png, Spine/fx crops,fonts.json,animated.json, andproblems.json. Non-emptyproblems.jsonor a non-zero exit = stop and read it.
2. Generate the Figma scripts
Section titled “2. Generate the Figma scripts”export UIFX_EXPORT=$X/export UIFX_LABEL="<Feature label>" UIFX_POPUPS=Prefab1,Prefab2 UIFX_SEC_X=0S=.claude/skills/t1k-unity-ui-figma-export/scriptspython3 $S/gen.py sprites && python3 $S/gen.py slice && python3 $S/gen.py ref && python3 $S/gen.py buildUIFX_SEC_X puts each feature in its own column (e.g. +7000 per feature). UIFX_LINE_HEIGHT is the TMP font’s faceInfo.lineHeight / pointSize in %; the default is 160.2 (Baloo2, the font gdk popups use). Read it from the font asset and set UIFX_LINE_HEIGHT when the project uses another font.
3. Run in Figma through Chrome
Section titled “3. Run in Figma through Chrome”-
Load the Chrome tools in one ToolSearch call (
tabs_context_mcp, navigate, javascript_tool, file_upload, find, computer). Open the user’s Figma file and switch to the target page in the UI. The scripts write tofigma.currentPage. -
javascript_tool← contents ofscripts/page-bootstrap.js. It must reportfigma: "object"; if it doesn’t, the tab is not a Figma design editor. -
find“t1k file drop” → the hidden input’s ref.file_uploadthe generated.jsfiles plus the PNGs they reference:sprites/<key>.png,render_*.png, and the Spine/fx crops. Keep each call under 10 MB and upload in batches. -
Run in this order, filling images after each step:
r = await t1kRun('sprites.js'); await t1kFillAll(r.created.map(([k,id]) => [id, k + '.png']))await t1kRun('slice.js')(rebuilds bordered sprites as 9 pieces)r = await t1kRun('ref.js'); await t1kFillAll(r.fills)- for each prefab:
r = await t1kRun('build_<P>.js'); await t1kFillAll(r.spines). Check thatr.missingis[].
Re-running a build replaces that prefab’s root, so it is safe to repeat. Sprite components are reused across features.
-
Verify by eye. Use
scrollAndZoomIntoView([refSection, layerSection]), then a zoomed screenshot. Compare each layer frame with its render. Fix defects ingen.pyand re-run the build; don’t hand-patch nodes, or the next rebuild loses the fix. Then check that no node was left at the page root (figma.currentPage.childrenare all SECTIONs).
Report to the user
Section titled “Report to the user”Give the section names and ids, the node counts, and every known gap you saw. Typical gaps: particles with no crop become empty [fx] frames; text shows prefab defaults, not live data; runtime-spawned children are missing; Timeline-animated elements show their pre-animation state; 9-slice is approximated with 9 pieces. Gotchas and fixes: references/hard-rules.md.
Executed by
Section titled “Executed by”Steps 1 and 2 are stored scripts with an exit-code or file gate, so they run on a cheap tier; the
Figma run and the visual check stay on a reasoning tier (routing SSOT: rules/orchestration-rules.md):
| Step | Agent |
|---|---|
Run run-export.sh / gen.py and report the exit code and problems.json | t1k-fact-fetcher |
| Upload files and run the generated scripts through Chrome, then compare each layer frame with its render | reasoning tier (t1k-fullstack-developer or the main session) |