Skip to content

t1k:unity:ui:figma-export

FieldValue
Moduleui
Version3.43.4
Efforthigh
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

/t1k:unity:ui:figma-export
<figma file url + page> <prefab dir> <Prefab1,Prefab2,...> [feature label]

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)”
SectionContent
<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.
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 page

All 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).

Terminal window
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/*.cs into Assets/Editor/_UiFigmaExport/, runs UiFigmaExport.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.sh exists. Otherwise it launches raw, which the PreToolUse unity guard only allows with the T1K_UNITY_RAW_LAUNCH_OK=1 prefix.
  • UIFX_ROOT_UI = the runtime root-canvas prefab whose CanvasScaler is copied (default Packages/com.gdk.core/Prefabs/CommonUIPrefab/RootUI.prefab, the gdk core root canvas; set UIFX_ROOT_UI to 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, and problems.json. Non-empty problems.json or a non-zero exit = stop and read it.
Terminal window
export UIFX_EXPORT=$X/export UIFX_LABEL="<Feature label>" UIFX_POPUPS=Prefab1,Prefab2 UIFX_SEC_X=0
S=.claude/skills/t1k-unity-ui-figma-export/scripts
python3 $S/gen.py sprites && python3 $S/gen.py slice && python3 $S/gen.py ref && python3 $S/gen.py build

UIFX_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.

  1. 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 to figma.currentPage.

  2. javascript_tool ← contents of scripts/page-bootstrap.js. It must report figma: "object"; if it doesn’t, the tab is not a Figma design editor.

  3. find “t1k file drop” → the hidden input’s ref. file_upload the generated .js files 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.

  4. 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 that r.missing is [].

    Re-running a build replaces that prefab’s root, so it is safe to repeat. Sprite components are reused across features.

  5. Verify by eye. Use scrollAndZoomIntoView([refSection, layerSection]), then a zoomed screenshot. Compare each layer frame with its render. Fix defects in gen.py and 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.children are all SECTIONs).

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.

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):

StepAgent
Run run-export.sh / gen.py and report the exit code and problems.jsont1k-fact-fetcher
Upload files and run the generated scripts through Chrome, then compare each layer frame with its renderreasoning tier (t1k-fullstack-developer or the main session)