Mockup to Unity UI
You turn a picture of a game screen into a real uGUI hierarchy (a prefab) and keep fixing it until it matches.
Tools
MCP server unity-ui-agent (see README for setup). If MCP is not connected, the same tools exist as node mcp/cli.mjs <build|screenshot|hierarchy|compare> ....
unity_build_ui(spec): builds the screen and savesAssets/UiAgent/Output/<name>.prefab.unity_screenshot(path?): renders at the exact canvas size.compare_to_mockup(mockup, render): pixel similarity, worst regions, diff image.unity_hierarchy(): what was built, with anchors.
Spec
{
"name": "level_complete",
"canvas": { "width": 540, "height": 960, "background": "#2b2d42" },
"elements": [
{ "id": "Window", "type": "panel", "rect": [40, 180, 460, 560], "color": "#edf2f4", "radius": 28 },
{ "id": "Title", "type": "text", "rect": [70, 160, 400, 60], "text": "LEVEL COMPLETE", "fontSize": 34, "color": "#ffffff", "bold": true },
{ "id": "Next", "type": "button", "rect": [100, 560, 340, 80], "color": "#06d6a0", "radius": 16, "text": "NEXT", "fontSize": 38, "bold": true }
]
}
rectis[x, y, width, height]in canvas pixels from the top-left corner. Canvas size = mockup size.- Types:
panel(box, optionalradius,outline,outlineWidth),button(box + label:text,fontSize,textColor),text(color,fontSize,align,bold),circle,progress(color= track,fill,value0..1, optionalradiusand label). - Styling on any box or circle:
gradient: bottom color of a vertical gradient that starts fromcolorat the top.shadow(color with alpha, e.g."#00000040"),shadowOffset(px down, default 6),shadowBlur(px, default 12). A hard "lip" under a game button isshadowBlur: 1withshadowOffset: 5.outline+outlineWidth: a border drawn inside the box that follows the rounded corners.
- One visual object = one element. Never add extra panels to imitate shadows, borders or gradients: use the fields above. Extra elements make the prefab harder to work with.
- Order matters: background panels first, then what sits on them, text last.
- Give every element a meaningful
id(PlayButton, CoinCount): they become GameObject names a developer will see.
Workflow
- Look at the mockup. Note its pixel size. List every element top to bottom: what it is, roughly where, what color, what text.
- Measure instead of guessing when it matters. You may read the PNG with a small script (for example sample colors or scan rows for edges with
pngjs) to get exact colors and edges. - Write the spec and call
unity_build_ui. Fix any error it returns. unity_screenshot, thencompare_to_mockup. Open both images and the diff. The worst regions tell you where to look.- Fix what is off: missing elements, wrong size or position, wrong color, wrong text, missing gradient or shadow. Rebuild. Stop after 3 rounds or when the result matches. Fonts differ from the mockup; size text by cap height, not by matching word width.
- Report: prefab path, final similarity, and anything you could not reproduce.
Pitfalls
- Text inside a colored bar is the bar's
text(button/progress), not a separate element, unless it is clearly separate. - Stars, coins, avatars and gems are
circleplaceholders with the right color. - A dimmed full-screen layer is a
panelwith the full canvas rect. - Keep
fontSizeclose to the cap height you see times ~1.4.