skills/cocos-ui-schema-generator/SKILL.md
Generate Cocos Creator 2.4 WebUI schema and supporting TypeScript files from screenshots, HTML, mockups, or textual UI descriptions. Use when building UI in projects that want to reuse the bundled WebUI runtime, when converting a design into `WebUINodeSchema`, when preparing AI-generated UI code for Cocos, or when a target project does not yet contain the required WebUI runtime files and they must be copied in first.
npx skillsauth add 958877748/skills cocos-ui-schema-generatorInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Generate UI as WebUINodeSchema-based TypeScript for the bundled Cocos WebUI runtime.
This skill includes a reusable runtime in assets/webui-runtime/. If the target Cocos project does not already contain these runtime files, copy them into the target project before generating schema or controller code.
The bundled runtime lives here:
assets/webui-runtime/types.tsassets/webui-runtime/style.tsassets/webui-runtime/layout.tsassets/webui-runtime/WebUIBackground.tsassets/webui-runtime/WebUIRenderer.tsassets/webui-runtime/WebUIExample.tsassets/webui-runtime/uiMeta.tsassets/webui-runtime/examples/withdrawExample.tsassets/webui-runtime/examples/withdrawExample1.tsUse these files as the source of truth when bootstrapping a new project.
The skill also includes helper scripts:
scripts/install-runtime.ps1scripts/validate-webui-schema.js.ts file exporting WebUINodeSchema data.WebUIRenderer.Before generating new UI files, verify whether the target project already contains equivalent runtime files such as WebUIRenderer.ts, layout.ts, style.ts, and types.ts.
If they do not exist, prefer using scripts/install-runtime.ps1 from this skill to copy the bundled runtime into a suitable location in the target Cocos project. Typical target location:
assets/scripts/webui/Prefer preserving the bundled file contents exactly unless the target project clearly requires path or naming adjustments.
PowerShell example:
powershell -ExecutionPolicy Bypass -File <skill>/scripts/install-runtime.ps1 -TargetProjectRoot <projectRoot>Prefer the following project layout when bootstrapping a plain Cocos Creator project:
assets/scripts/webui/assets/scripts/If runtime is installed under assets/scripts/webui/ and generated page files are placed under assets/scripts/, use these relative imports:
import { WebUINodeSchema } from './webui/types';import { WebUIMeta } from './webui/uiMeta';import WebUIRenderer from './webui/WebUIRenderer';Do not guess import paths blindly. Compute imports from the actual generated file location relative to the runtime location.
If the target project uses a different directory layout, adjust imports accordingly, but keep runtime imports consistent within the generated files.
Generate TypeScript, not raw JSON, unless the user explicitly asks for JSON.
Preferred output shape:
WithdrawPanel.schema.tsexport const withdrawPanelSchema: WebUINodeSchema = { ... }export const withdrawPanelMeta: WebUIMeta = { ... }If a controller is requested, generate a separate component file, e.g. WithdrawPanel.ts, that:
cc.ComponentWebUIRendererrenderer.getNodeById(id) or renderer.getNodesByIds(ids) when the bundled runtime is presentDo not treat WebUIExample.ts as a required business base class. It is only an example reference.
Only generate these node types unless the runtime has been explicitly extended:
viewtextimageDo not invent unsupported nodes such as:
buttoninputscrollrichTextsvgvideoRepresent buttons and clickable areas as view or text nodes with stable ids that business code can bind events to later.
Only use style fields supported by the bundled runtime:
displaypositionflexDirectionjustifyContentalignItemsalignSelfflexWrapflexGrowflexShrinkflexBasisgapwidthheightminWidthminHeightmaxWidthmaxHeightpaddingmarginpaddingToppaddingRightpaddingBottompaddingLeftmarginTopmarginRightmarginBottommarginLeftleftrighttopbottomzIndexbackgroundColoropacityborderRadiusfontSizefontWeightcolorlineHeighttextAlignwhiteSpaceoverflowobjectFitDo not generate unsupported CSS-like fields such as border, boxShadow, transform, grid, filter, letterSpacing, or lineClamp unless the user explicitly asks to extend the runtime too.
When the source design contains unsupported CSS-like effects, do not simply copy those fields into schema. Use the following fallback strategy.
borderTop, borderBottom, or similar single-edge border:
view node, usually height 1, width '100%', and a suitable backgroundColorborder around a block:
view uses the border color and border radiusview uses the content background color and inner padding or margin to simulate the border thicknessviews rather than unsupported border fieldsboxShadow:
boxShadow directly unless runtime support is explicitly addedlinear-gradient or other gradient backgrounds:
transform, scale, rotate, translate:
overflow: hidden for card masking:
Always prefer a visually close, runtime-compatible structure over copying unsupported fields.
Prefer flex layout over absolute positioning.
Use position: 'absolute' only for clear overlay cases such as:
For normal structure, prefer:
viewsflexDirectiongappaddingmarginAvoid unnecessary nesting. Keep hierarchy shallow while preserving meaningful groups such as header, content, footer, card, row, and action area.
Assign stable ids to all business-relevant nodes.
Ids are required for:
Use lower camel case and semantic prefixes when useful:
btnSubmitbtnBacktxtAmounttxtTitleimgAvatarpanelMainlistRewardsDo not rename existing ids during edits unless the user explicitly requests it.
Generate a lightweight WebUIMeta object alongside the schema for business-facing pages.
Import source:
assets/webui-runtime/uiMeta.tsCurrent supported fields:
interactiveIdsdynamicTextIdsdynamicImageIdscontainerIdsUse interactiveIds for clickable nodes such as back, close, submit, invite, tab, and card entry areas.
Use dynamicTextIds for text nodes whose content may change later, such as title, amount, username, countdown, status text, and button label.
Use dynamicImageIds for images that business code may replace later, such as avatar, banner, product, and reward art.
Use containerIds for nodes that business code may access to inject, replace, or toggle content, such as main panel, content panel, empty panel, loading panel, and list container.
Keep WebUIMeta lightweight. Do not try to encode full business logic into it.
If asked to generate a controller component, prefer this structure:
onLoad() or start() ensures a WebUIRenderer existscacheNodes() optionally stores important node references after renderbindEvents() attaches click handlers for interactive idsupdateAmount(), updateTitle(), or setLoadingVisible() modify UI using ids or cached refsAdditional rules:
WebUIRendererWebUIMeta when presentrenderer.getNodeById('someId') when using the bundled runtimeclaimToBagMeta.interactiveIds or similar meta fields exist, keep controller logic aligned with those ids rather than inventing unrelated namesWhen revising an existing schema:
The bundled runtime is suitable for prototype and moderate business UI, but not full browser compatibility.
Important limitations to respect while generating:
view, text, image are supportedflexWrap is typed but not fully implemented for production usageflexShrink support is incompleteoverflow: hidden is not fully implemented as a generic container clipping systemWhen the design depends on unsupported features, simplify the UI or explicitly tell the user that the runtime must be extended.
For screenshot-to-UI or mockup-to-UI tasks:
WebUINodeSchema tree.When schema or meta is available in machine-readable JSON form for checking, validate it with scripts/validate-webui-schema.js when practical. The validator checks:
props.text for textprops.src for imageIf the current repository does not contain the WebUI runtime, do not stop at schema generation. First copy the bundled runtime assets from this skill into the target project, then generate the schema, meta, and any requested controller files.
tools
Cocos Creator 2.4.x 场景/预制体命令行工具,支持读写 .fire/.prefab、JSON 生成 UI、截图预览
development
查询公网IP地址的地理位置信息,包括国家、省份、城市、ISP、时区等
tools
Cocos Creator 有限状态机 (FSM) 实现,用于管理游戏对象的状态转换
tools
Cocos Creator 2.4.x 粒子系统修饰器开发框架。用于创建、使用和调试自定义粒子修饰器,支持修改粒子位置、颜色、大小、旋转、速度等属性。当需要在 Cocos Creator 中实现复杂的粒子效果控制时使用此技能。