cocos-vscene

📁 jerikchan/cocos-vscene 📅 8 days ago
1
总安装量
1
周安装量
#44270
全站排名
安装命令
npx skills add https://github.com/jerikchan/cocos-vscene --skill cocos-vscene

Agent 安装分布

replit 1
amp 1
opencode 1
cursor 1
codex 1

Skill 文档

Cocos VScene – Scene Index & Analysis System

Design Philosophy

VScene = Index (索引) + Analysis (分析)

┌─────────────────────────────────────────────────────────────┐
│                    VScene System                            │
├─────────────────────────┬───────────────────────────────────┤
│   Index Layer (索引层)   │      Analysis Layer (分析层)      │
├─────────────────────────┼───────────────────────────────────┤
│ • Fast lookup           │ • Structure quality scoring       │
│ • Node/Component cache  │ • Code-scene relation analysis    │
│ • Offline capable       │ • Business module identification  │
│ • Minimal context       │ • Self-check & iteration          │
└─────────────────────────┴───────────────────────────────────┘
Principle Description
Index only Store name, path, component types – NOT property values
Query on demand Fetch details via MCP when needed
Progressive load Load large scenes in layers
AI friendly Minimal structure for fast lookup
Quality scoring Rate structure and code-scene relations
Self-iterating Support review and improvement suggestions

Commands

Command MCP Description
vscene pull ✅ Build/update index from editor
vscene read [--depth N] ❌ Read from cache (default depth: 3)
vscene find <pattern> ❌ Search nodes by name/type
vscene detail <uuid> ✅ Get full node properties
vscene diff ✅ Compare index vs real scene
vscene status ❌ View index status
vscene analyze ✅ Generate quality analysis with scoring
vscene review ❌ Self-check analysis, suggest improvements
vscene pretty ✅ Analyze hierarchy, propose & execute optimizations

Directory Structure

.vscene/
├── manifest.json                    # Scene manifest (场景清单)
├── scenes/
│   └── {sceneName}.json             # Scene index (场景索引)
└── analysis/
    └── {sceneName}.analysis.md      # Quality analysis (质量分析)

Index Layer (索引层)

VNode Format (Enhanced)

{
  "u": "uuid",
  "n": "NodeName",
  "c": ["GameManager", "AudioSource"],
  "k": true,
  "d": 0,
  "role": "logic",
  "desc": "游戏逻辑根节点",
  "_": []
}
Field Full name Description
u uuid Node UUID
n name Node name
c components Component type names (excludes cc.* engine)
k key Is key node (has important components)
d depth Hierarchy depth
role role Node role: logic/ui/render/data/container
desc description One-line description (中文)
_ children Child nodes array

Node Role Classification

Role Description Examples
logic Business logic, controllers GameManager, PlayerController
ui User interface elements Canvas, Button, Label
render Visual elements only MeshRenderer, Sprite (no script)
data Data containers ConfigNode, AssetsNode
container Organizational grouping Managers, World, UI

Analysis Layer (分析层)

analyze Command Flow

vscene analyze
  │
  ├─ Step 1: Check/Load Index
  │   └─ If no index → auto pull
  │
  ├─ Step 2: Structure Analysis (结构分析)
  │   ├─ Hierarchy depth analysis
  │   ├─ Node naming conventions
  │   ├─ Module organization
  │   └─ Component distribution
  │
  ├─ Step 3: Code-Scene Relation Analysis (代码-场景关系分析)
  │   ├─ Grep: getChildByName / find patterns
  │   ├─ Grep: getComponent patterns
  │   ├─ Match code references to scene nodes
  │   └─ Identify missing/orphan references
  │
  ├─ Step 4: Quality Scoring (质量评分)
  │   ├─ Structure Score (结构分)
  │   ├─ Naming Score (命名分)
  │   ├─ Code-Scene Coupling Score (耦合分)
  │   └─ Overall Score (总分)
  │
  ├─ Step 5: Generate Issues & Suggestions (问题与建议)
  │   ├─ Critical issues (严重��题)
  │   ├─ Warnings (警告)
  │   └─ Improvement suggestions (改进建议)
  │
  └─ Output: .vscene/analysis/{sceneName}.analysis.md

Quality Scoring System (评分体系)

Total Score: 100 points

Dimension Weight Criteria
Structure (结构) 30 Hierarchy depth, module organization, node grouping
Naming (命名) 20 Consistent naming, semantic clarity, no magic names
Code-Scene (代码-场景) 30 Clean references, no hardcoded paths, proper coupling
Maintainability (可维护性) 20 Component reuse, prefab usage, separation of concerns

Scoring Rules

Structure Score (30 points)

Rule Points Deduction
Max depth ≤ 6 +10 -2 per level over 6
Logic nodes grouped under one root +10 -5 if scattered
UI nodes under Canvas +5 -5 if mixed
Clear module separation +5 -2 per violation

Naming Score (20 points)

Rule Points Deduction
PascalCase for nodes +5 -1 per violation
Semantic names (not node1, node2) +5 -2 per violation
Consistent prefixes (e.g., UI_, Btn_) +5 -1 per inconsistency
Chinese comments for key nodes +5 -1 per missing

Code-Scene Score (30 points)

Rule Points Deduction
No hardcoded getChildByName paths >2 levels +10 -2 per violation
Scene references match actual nodes +10 -5 per orphan ref
Components attached to appropriate nodes +5 -2 per misplacement
Events properly scoped +5 -2 per global leak

Maintainability Score (20 points)

Rule Points Deduction
Prefab usage for repeated structures +5 -2 per copy-paste
Single responsibility per component +5 -2 per god component
No circular references +5 -5 per cycle
Clear data flow direction +5 -2 per unclear flow

Score Levels

Score Level Emoji Description
90-100 Excellent 🌟 Production ready, well architected
75-89 Good ✅ Minor issues, acceptable
60-74 Fair ⚠️ Needs improvement before release
40-59 Poor ❌ Significant refactoring needed
0-39 Critical 🚨 Architectural problems, redesign required

review Command (Self-Check & Iterate)

vscene review
  │
  ├─ Step 1: Load existing analysis
  │
  ├─ Step 2: Verify issues still exist
  │   └─ Re-check each reported issue
  │
  ├─ Step 3: Check if suggestions implemented
  │   └─ Compare with previous analysis
  │
  ├─ Step 4: Update scores
  │   └─ Recalculate based on current state
  │
  └─ Output: Updated analysis with delta

Review Output Example:

## Review: gameScene

### Score Change
| Dimension | Previous | Current | Delta |
|-----------|----------|---------|-------|
| Structure | 22/30 | 25/30 | +3 ✅ |
| Naming | 12/20 | 15/20 | +3 ✅ |
| Code-Scene | 20/30 | 20/30 | 0 |
| Total | 64/100 | 70/100 | +6 ✅ |

### Resolved Issues
- ✅ [S-001] node1 renamed to Environment
- ✅ [N-002] Added Chinese comments

### Remaining Issues
- ⚠️ [C-001] Still has hardcoded path in PlayerController.ts:45

pretty Command (Hierarchy Optimization)

Core Workflow: Analyze → Propose → Confirm → Execute

vscene pretty
  │
  ├─ Phase 1: Analysis (分析阶段)
  │   ├─ Check/Load index (auto pull if needed)
  │   ├─ Detect naming issues (node1, New Node, etc.)
  │   ├─ Detect hierarchy issues (depth > 6, scattered nodes)
  │   ├─ Detect structure issues (ungrouped, mixed concerns)
  │   └─ Generate issue list with severity
  │
  ├─ Phase 2: Proposal (方案生成)
  │   ├─ Generate optimization operations
  │   │   ├─ Rename operations (重命名)
  │   │   ├─ Reparent operations (调整父节点)
  │   │   ├─ Reorder operations (调整顺序)
  │   │   └─ Group operations (分组整理)
  │   ├─ Preview before/after structure
  │   └─ Estimate impact (affected nodes count)
  │
  ├─ Phase 3: Confirmation (用户确认) ⏸️
  │   ├─ Display proposal to user
  │   ├─ Wait for user decision:
  │   │   ├─ "同意" / "执行" → Proceed to Phase 4
  │   │   ├─ "修改" + feedback → Revise proposal
  │   │   └─ "取消" → Abort
  │   └─ User can select specific operations
  │
  └─ Phase 4: Execution (执行阶段)
      ├─ Execute via MCP node_modify
      ├─ Batch operations for efficiency
      ├─ Update local index
      └─ Output: Execution summary

Optimization Rules (优化规则)

1. Naming Optimization (命名优化)

Pattern Issue Suggested Fix
node, node1, node2 无意义命名 根据子节点/组件推断语义名
New Node, Node 默认名称 根据上下文推断
节点1, 测试 临时命名 提示用户提供语义名
Mixed case (playerNode) 大小写不规范 PlayerNode (PascalCase)

2. Hierarchy Optimization (层级优化)

Issue Criteria Action
过深层级 depth > 6 提升到合适父节点
单子节点链 A→B→C (each has 1 child) 扁平化,合并中间节点
散落逻辑节点 Logic nodes under render 移动到 LogicRoot
散落 UI 节点 UI nodes outside Canvas 移动到 Canvas 下

3. Structure Optimization (结构优化)

Issue Criteria Action
未分组 >10 siblings at root 按类型分组到容器
混合关注点 UI + Logic + Render mixed 分离到不同容器
重复结构 Similar node patterns 建议转为 Prefab

Proposal Output Format (方案输出格式)

## VScene Pretty: gameScene

### 检测到的问题 (Issues Found)

| # | 类型 | 节点 | 问题 | 严重度 |
|---|------|------|------|--------|
| 1 | 命名 | `node1` | 无意义命名 | ⚠️ |
| 2 | 命名 | `New Node` | 默认名称 | ⚠️ |
| 3 | 层级 | `A/B/C/D/E/F/G` | 层级过深 (7层) | ❌ |
| 4 | 结构 | `Canvas/PlayerCtrl` | 逻辑组件在UI容器下 | ⚠️ |

### 优化方案 (Optimization Plan)

#### 重命名操作 (Rename)
| # | 原名称 | 新名称 | UUID |
|---|--------|--------|------|
| R1 | `node1` | `Environment` | abc123 |
| R2 | `New Node` | `GameManager` | def456 |

#### 层级调整 (Reparent)
| # | 节点 | 原父节点 | 新父节点 | 原因 |
|---|------|----------|----------|------|
| P1 | `PlayerCtrl` | `Canvas` | `LogicRoot` | 逻辑组件应在逻辑容器 |
| P2 | `DeepNode` | `A/B/C/D/E/F` | `A/B` | 层级扁平化 |

#### 分组操作 (Group)
| # | 新容器 | 包含节点 | 原因 |
|---|--------|----------|------|
| G1 | `Managers` | `GameMgr, AudioMgr, UIMgr` | 管理器分组 |

### 预览 (Preview)

**Before:**

gameScene ├─ node1 ├─ New Node [GameManager] ├─ Canvas │ └─ PlayerCtrl [PlayerController] ⚠️ └─ A/B/C/D/E/F/G ❌


**After:**

gameScene ├─ Environment (原 node1) ├─ LogicRoot │ ├─ GameManager (原 New Node) │ └─ PlayerCtrl ✅ ├─ Canvas └─ A/B/DeepNode ✅


### 影响范围
- 重命名: 2 个节���
- 移动: 2 个节点
- 新建容器: 1 个

---
**请确认是否执行以上优化?**
- 输入 `同意` 或 `执行` 执行全部操作
- 输入 `执行 R1 P1` 执行指定操作
- 输入 `修改` + 反馈 调整方案
- 输入 `取消` 放弃优化

Execution Output (执行结果)

## 执行完成 ✅

### 执行结果
| # | 操作 | 状态 |
|---|------|------|
| R1 | `node1` → `Environment` | ✅ 成功 |
| R2 | `New Node` → `GameManager` | ✅ 成功 |
| P1 | `PlayerCtrl` → `LogicRoot` | ✅ 成功 |

### 索引已更新
场景已保存,建议运行 `vscene analyze` 查看优化后评分。

Analysis Document Template

See references/analysis-template.md for full template.

Key Sections

  1. Header – Scene name, stats, score summary
  2. Score Card – Detailed scoring breakdown
  3. Structure Overview – Annotated hierarchy tree
  4. Module Analysis – Business module identification
  5. Code-Scene Relations – Reference mapping table
  6. Issues & Suggestions – Prioritized improvement list
  7. Iteration Log – Review history

Quick Start

First Analysis

vscene pull              # Build index
vscene analyze           # Generate analysis
# Review .vscene/analysis/{scene}.analysis.md

Iterate on Quality

# Make improvements to scene...
vscene review            # Check progress
vscene analyze           # Full re-analysis

Auto Optimization

vscene pretty            # Analyze and propose optimizations
# Review proposal, then:
# - "同意" to execute all
# - "执行 R1 P1" to execute specific operations
# - "修改" + feedback to revise
# - "取消" to abort

Check Specific Issues

vscene find node*        # Find poorly named nodes
vscene detail <uuid>     # Inspect specific node

Index Output Format

vscene read (depth: 3)

## VScene: gameScene (226 nodes, depth 8)
Cached: 2026-01-26 | Score: 72/100 ⚠️

gameScene                           # 场景根节点
├─ Main Light [DirectionalLight]    # 主光源
├─ Main Camera [CameraComponent]    # 主相机
├─ Canvas [Canvas] ★                # UI 画布
│  ├─ JoystickUI                   # 摇杆控制
│  └─ DragtoMove                   # 拖拽提示
├─ node1                           # ⚠️ 命名不规范
│  └─ [+36 nodes]
└─ LogicRoot ★                     # 逻辑根节点
   ├─ Player ★                     # 玩家角色
   ├─ Unlock ★                     # 解锁系统
   └─ UnlockBuildings ★            # 可解锁建筑

★ = Key node | ⚠️ = Has issues | [+N] = Collapsed

Key Node Detection

Nodes with these components are marked as key (k: true):

Priority 1 (Always):

  • *Manager, *Controller, *System, Root
  • *Assets, *Factory, *Spawner

Priority 2 (Business):

  • *Trigger, *Handler, *Generator
  • Any custom component (not cc.* prefixed)

Detailed References


Error Handling

Scenario Handling
MCP disconnected + has cache read/find/status/review work offline
MCP disconnected + no cache Error, prompt to start editor
MCP disconnected + analyze Error, MCP required for full analysis
Index corrupted Auto rebuild
Analysis outdated Warn on read, suggest re-analyze