← Back to Plugins
Tools

Cocos Auto Builder

Openclawquinnquinnquinn By Openclawquinnquinnquinn 👁 47 views ▲ 0 votes

OpenClaw AI Agent automation plugin for Cocos Creator

GitHub

Configuration Example

{
  "action": "get_current_scene",
  "params": {}
}

README

# OpenClaw Cocos Auto Builder

让 OpenClaw AI Agent 直接操作 Cocos Creator 的编辑器插件。

## 安装

1. 将此目录复制到你的 Cocos Creator 项目的 `extensions/` 文件夹:

```bash
cp -r cocos-auto-builder /path/to/your-cocos-project/extensions/openclaw-auto-builder
```

2. 重启 Cocos Creator

3. 插件会自动启动 HTTP 服务器(端口 19876)

## 使用方法

### 健康检查

```bash
curl http://localhost:19876/health
```

### 执行任务

所有操作通过 POST 请求发送 JSON:

```bash
curl -X POST http://localhost:19876/execute \
  -H "Content-Type: application/json" \
  -d '{"action": "get_current_scene", "params": {}}'
```

## 支持的操作

### 1. 获取当前场景信息

```json
{
  "action": "get_current_scene",
  "params": {}
}
```

### 2. 创建节点

```json
{
  "action": "create_node",
  "params": {
    "name": "PuzzleHUD",
    "parent": null,
    "components": ["cc.Widget"],
    "properties": {
      "cc.Widget": {
        "top": 0,
        "bottom": 0,
        "left": 0,
        "right": 0
      }
    },
    "children": [
      {
        "name": "TopBar",
        "components": ["cc.Widget", "cc.Sprite"],
        "properties": {
          "cc.Widget": { "top": 0, "left": 0, "right": 0, "height": 150 }
        },
        "children": [
          {
            "name": "Btn_Back",
            "components": ["cc.Button", "cc.Sprite"]
          },
          {
            "name": "Btn_Reset",
            "components": ["cc.Button", "cc.Sprite"]
          }
        ]
      }
    ]
  }
}
```

### 3. 添加组件

```json
{
  "action": "add_component",
  "params": {
    "nodeUuid": "节点UUID",
    "component": "cc.Button",
    "properties": {
      "transition": 2
    }
  }
}
```

### 4. 设置属性

```json
{
  "action": "set_property",
  "params": {
    "nodeUuid": "节点UUID",
    "component": "cc.Widget",
    "property": "top",
    "value": 20
  }
}
```

### 5. 批量构建

```json
{
  "action": "build_from_json",
  "params": {
    "nodes": [
      {
        "name": "TopBar",
        "components": ["cc.Widget"],
        "properties": { "cc.Widget": { "top": 0 } }
      },
      {
        "name": "CompletePanel",
        "components": ["cc.Sprite"],
        "children": [...]
      }
    ]
  }
}
```

### 6. 自动绑定属性

根据节点名称自动绑定脚本属性:

```json
{
  "action": "auto_bind_properties",
  "params": {
    "nodeUuid": "挂载脚本的节点UUID",
    "script": "M01_GearPuzzle",
    "bindings": {
      "backButton": "Btn_Back",
      "resetButton": "Btn_Reset",
      "titleLabel": "Label_Title"
    }
  }
}
```

### 7. 创建预制体

```json
{
  "action": "create_prefab",
  "params": {
    "name": "PuzzleHUD",
    "path": "assets/resources/prefabs/PuzzleHUD.prefab",
    "nodes": [...]
  }
}
```

### 8. 实例化预制体

```json
{
  "action": "instantiate_prefab",
  "params": {
    "prefabPath": "assets/resources/prefabs/PuzzleHUD.prefab",
    "parentUuid": "Canvas的UUID"
  }
}
```

### 9. 项目配置

```json
{
  "action": "set_project_config",
  "params": {
    "designWidth": 1080,
    "designHeight": 1920,
    "fitWidth": true,
    "fitHeight": false
  }
}
```

## 组件名称映射

简写会自动转换:
- `Widget` → `cc.Widget`
- `Sprite` → `cc.Sprite`
- `Button` → `cc.Button`
- `Label` → `cc.Label`
- `UITransform` → `cc.UITransform`

## 菜单操作

在 Cocos Creator 菜单栏:
- **OpenClaw → 启动自动化服务**
- **OpenClaw → 停止自动化服务**
- **OpenClaw → 执行施工任务**(弹出输入框,手动输入 JSON)

## 故障排除

1. **端口被占用**:修改 `src/main.ts` 中的 `PORT` 常量
2. **操作无响应**:检查 Cocos Creator 控制台的错误日志
3. **找不到节点**:确保场景已打开且节点名称正确

## 安全提示

此插件仅供本地开发使用。默认绑定所有网络接口,请勿在生产环境使用。
tools

Comments

Sign in to leave a comment

Loading comments...