thrift-related/PythonWorkSpace/IntegratedTool/PROJECT.md
2026-01-12 19:24:48 +08:00

4.5 KiB
Raw Blame History

Thrift 完整流程工具 - 项目结构

文件说明

IntegratedTool/
├── integrated_pipeline.py          # 主程序
├── pipeline_config.json            # 配置文件(自动生成)
├── requirements.txt                # Python 依赖
├── README.md                       # 使用说明
├── cfg_txt_example.json           # 配置示例
├── 启动工具.bat                    # 快速启动
├── 安装依赖.bat                    # 安装依赖包
├── 打包集成工具.bat                # 打包为 EXE
└── gen-py/                        # 临时目录(自动清理)

快速开始

1. 安装依赖

安装依赖.bat

或手动安装:

pip install openpyxl thrift pyinstaller

2. 启动工具

启动工具.bat

或直接运行:

python integrated_pipeline.py

3. 配置路径

首次运行需要配置以下路径:

  • cfg_txt.json 配置文件
  • Thrift 编译器 (thrift.exe)
  • Thrift 文件路径(生成的 .thrift 存放位置)
  • C# 输出路径(临时)
  • Bytes 输出路径(临时)
  • Config 路径Excel 文件夹)
  • Unity C# 路径(最终目标)
  • Unity Bytes 路径(最终目标)

4. 执行流程

点击"开始执行完整流程"按钮

打包为 EXE

自动打包

打包集成工具.bat

手动打包

pyinstaller --onefile --noconsole --name=ThriftPipeline ^
    --hidden-import=openpyxl ^
    --hidden-import=thrift ^
    --hidden-import=thrift.protocol.TBinaryProtocol ^
    --hidden-import=thrift.transport.TTransport ^
    integrated_pipeline.py

打包后的 EXE 位于:../../IntegratedToolEXE/ThriftPipeline.exe

执行流程详解

阶段1生成 Thrift 文件

  • 读取 cfg_txt.json 配置
  • 遍历每个 Excel 文件
  • 解析表头和类型
  • 生成对应的 .thrift 文件

阶段2编译到 C#

  • 调用 thrift.exe 编译器
  • 使用参数:-strict -v -r --gen netstd:unity,serial,async_postfix
  • 生成 Unity C# 代码

阶段3生成 Bytes 文件

  • 编译 Thrift 到 Pythongen-py
  • 读取 Excel 数据
  • 使用 TBinaryProtocol 序列化
  • 生成 .bytes 二进制文件

阶段4清理 Extensions

  • 删除多余的 .Extensions.cs 文件
  • 保留 AllConfigs.Extensions.cs

阶段5复制 C# 到 Unity

  • 将所有 .cs 文件复制到 Unity C# 目录
  • 覆盖旧文件

阶段6复制 Bytes 到 Unity

  • 将所有 .bytes 文件复制到 Unity Bytes 目录

阶段7清理临时文件

  • 删除 gen-py 目录

配置文件格式

cfg_txt.json

{
  "file_list": [
    {
      "in_file": "Music.xlsx",      // Excel 文件名
      "out_file": "Music.txt",       // 输出文件名(决定结构名)
      "sheet_name": "Music"          // Sheet 名称
    }
  ]
}

pipeline_config.json自动生成

{
  "cfg_json_path": "path/to/cfg_txt.json",
  "compiler_path": "path/to/thrift.exe",
  "thrift_dir": "path/to/thrift-files",
  "csharp_output_dir": "path/to/csharp-output",
  "bytes_output_dir": "path/to/bytes-output",
  "config_dir": "path/to/excel-files",
  "unity_csharp_dir": "path/to/unity/csharp",
  "unity_bytes_dir": "path/to/unity/bytes"
}

Excel 格式要求

| Id | AssetName | ... |  <- 第1行字段名
| int | string | ... |     <- 第2行类型
| 1 | music_01 | ... |     <- 第3行起数据
| 2 | music_02 | ... |

类型映射

  • int → i32
  • long → i64
  • float/double → double
  • string → string
  • bool → bool

报告说明

每次执行完成后生成报告文件:

  • 文件名:report_YYYYMMDD_HHMMSS.txt
  • 位置:工具所在目录
  • 内容:每个步骤的状态、时间、详细数据

常见问题

Q: gen-py 目录会一直存在吗?

A: 不会,每次执行完自动清理。下次运行重新生成。

Q: 为什么需要临时的 C# 和 Bytes 输出目录?

A: 方便检查生成结果,确认无误后再复制到 Unity。

Q: AllConfigs.Extensions.cs 为什么要保留?

A: 因为 AllConfigs 引用了其他配置,需要这个扩展类。

Q: 能否跳过某些步骤?

A: 目前不支持,建议完整执行。如需单独步骤,使用其他专用工具。

Q: 报告文件能删除吗?

A: 可以,不影响工具运行。建议保留最近几次的报告便于排查问题。

技术栈

  • GUI: tkinter
  • Excel: openpyxl
  • Thrift: Apache Thrift
  • 序列化: TBinaryProtocol
  • 打包: PyInstaller

开发者信息

  • 版本v1.0
  • 创建日期2026-01-11
  • Python 版本3.7+