---
globs: "*.cpp,*.h,*.cs"
---

# Unreal 插件开发规范

## 插件结构

```
UnrealProjectAnalyzer/ (插件根目录)
├── UnrealProjectAnalyzer.uplugin         # 插件描述文件
├── Source/UnrealProjectAnalyzer/
│   ├── Public/                        # 头文件
│   ├── Private/                       # 实现文件
│   └── UnrealProjectAnalyzer.Build.cs
└── Content/Python/                    # Python Bridge 脚本
```

## 模块职责

| 文件 | 职责 |
|------|------|
| `UnrealProjectAnalyzer.cpp/h` | 模块入口，HTTP Server 初始化 |
| `BlueprintAnalyzer.cpp/h` | Blueprint 分析逻辑 |
| `AssetAnalyzer.cpp/h` | Asset 引用分析逻辑 |
| `HttpRoutes.cpp/h` | HTTP 路由注册 |

## HTTP API 设计

### Blueprint API

```
GET /blueprint/search?pattern=xxx&class=xxx
GET /blueprint/hierarchy?bp_path=/Game/...
GET /blueprint/dependencies?bp_path=/Game/...
GET /blueprint/referencers?bp_path=/Game/...
GET /blueprint/graph?bp_path=/Game/...&graph_name=EventGraph
GET /blueprint/details?bp_path=/Game/...
```

### Asset API

```
GET /asset/search?pattern=xxx&type=xxx
GET /asset/references?asset_path=/Game/...
GET /asset/referencers?asset_path=/Game/...
GET /asset/metadata?asset_path=/Game/...
```

### Analysis API

```
GET /analysis/reference-chain?start=xxx&depth=xxx
GET /analysis/cpp-class-usage?class=xxx
```

## 编码规范

### 命名

- 类: `F` 前缀 (struct), `U` 前缀 (UObject), `A` 前缀 (Actor)
- 模块类: `FUnrealProjectAnalyzerModule`
- 布尔值: `b` 前缀 (`bIsEnabled`)

### 日志

```cpp
UE_LOG(LogTemp, Log, TEXT("UnrealProjectAnalyzer: Message"));
UE_LOG(LogTemp, Warning, TEXT("UnrealProjectAnalyzer: Warning"));
UE_LOG(LogTemp, Error, TEXT("UnrealProjectAnalyzer: Error"));
```

### HTTP 路由注册

```cpp
Router->BindRoute(
    FHttpPath(TEXT("/endpoint")),
    EHttpServerRequestVerbs::VERB_GET,
    [](const FHttpServerRequest& Request, const FHttpResultCallback& OnComplete)
    {
        // 处理请求
        TUniquePtr<FHttpServerResponse> Response = FHttpServerResponse::Create(
            TEXT("{\"key\": \"value\"}"),
            TEXT("application/json")
        );
        OnComplete(MoveTemp(Response));
        return true;
    }
);
```

## Python Bridge

Python Bridge 通过 `PythonScriptPlugin` 在模块启动时自动拉起：

```cpp
// 在 StartupModule() 中
IPythonScriptPlugin* PythonPlugin = FModuleManager::GetModulePtr<IPythonScriptPlugin>("PythonScriptPlugin");
PythonPlugin->ExecPythonCommand(*PythonCommand);
```

## 依赖模块

必需的 UE 模块 (在 Build.cs 中声明)：
- `HTTP`, `HTTPServer` - HTTP 服务
- `Json`, `JsonUtilities` - JSON 处理
- `UnrealEd`, `BlueprintGraph`, `Kismet` - 蓝图 API
- `AssetRegistry` - 资产引用 API
- `PythonScriptPlugin` - Python 集成

## 路由参数约定（重要）

- **含 `/Game/...` 的资产/蓝图路径必须使用 query 参数传递**（例如 `bp_path=/Game/...`、`asset_path=/Game/...`）
- **不要**把 `/Game/...` 直接拼进 URL path（如 `/blueprint/{path}/hierarchy`），因为 UE `HttpServer` 的路由匹配会按 `/` 分段，容易导致无法匹配或编码/解码异常。
