T2FGame.Tools 0.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package T2FGame.Tools --version 0.0.1
                    
NuGet\Install-Package T2FGame.Tools -Version 0.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="T2FGame.Tools" Version="0.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="T2FGame.Tools" Version="0.0.1" />
                    
Directory.Packages.props
<PackageReference Include="T2FGame.Tools" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add T2FGame.Tools --version 0.0.1
                    
#r "nuget: T2FGame.Tools, 0.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package T2FGame.Tools@0.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=T2FGame.Tools&version=0.0.1
                    
Install as a Cake Addin
#tool nuget:?package=T2FGame.Tools&version=0.0.1
                    
Install as a Cake Tool

T2FGame.Tools

T2FGame 开发工具库,提供 Proto 导出、客户端 SDK 代码生成等功能。

功能

  • ProtoExporter:从编译后的程序集中导出 .proto 文件
  • ClientSdkGenerator:为 Unity 客户端生成类型安全的 SDK 代码

安装

<PackageReference Include="T2FGame.Tools" />

CLI 工具

安装全局工具:

dotnet tool install -g T2FGame.Tools.Cli

导出 Proto 文件

t2f-proto export -a ./bin/Debug/net9.0/MyGame.dll -o ./protos

生成客户端 SDK

t2f-proto sdk -a ./bin/Debug/net9.0/MyGame.dll -o ./unity/Assets/Gen -n CardsRPG.Gen

使用方法

ProtoExporter

从编译后的程序集中提取 Source Generator 生成的 .proto 文件:

using T2FGame.Tools;

var exporter = new ProtoExporter();

// 导出 .proto 文件
var result = exporter.Export(
    assemblyPath: "./bin/Debug/net9.0/MyGame.dll",
    outputDirectory: "./protos",
    cleanOutput: true);

if (result.Success)
{
    Console.WriteLine($"成功导出 {result.FileCount} 个文件");
}

ClientSdkGenerator

为 Unity 客户端生成类型安全的 SDK 代码:

using T2FGame.Tools.ClientSdk;

var generator = new ClientSdkGenerator();
var options = new ClientSdkOptions
{
    ClientNamespace = "CardsRPG.Gen",
    ProtoNamespace = "CardsRPG.Gen.Proto"
};

var result = generator.Generate(
    assemblyPath: "./bin/Debug/net9.0/MyGame.dll",
    outputDirectory: "./unity/Assets/Gen",
    options: options);

if (result.Success)
{
    Console.WriteLine($"成功生成 {result.GeneratedFiles.Count} 个文件");
}

生成的客户端代码

Action 类

每个服务器模块生成一个对应的 Action 类,包含回调和 async/await 两种调用方式:

// 回调方式
UserAction.OfLogin(request, result => {
    var value = result.GetValue<LoginResponse>();
});

// async/await 方式
var result = await UserAction.OfAwaitLogin(request);
var value = result.GetValue<LoginResponse>();

Listener 类

统一的广播消息监听器:

Listener.ListenUserInfoUpdate(result => {
    var userInfo = result.GetValue<UserInfo>();
});

GameCode 类

错误码常量和描述:

if (result.ErrorCode == GameCode.UserNotFound)
{
    // 处理用户不存在错误
}

目录结构

T2FGame.Tools/
├── ProtoExporter.cs           # Proto 文件导出器
└── ClientSdk/
    ├── ClientSdkModels.cs     # 模型定义
    ├── ClientSdkExtractor.cs  # 元数据提取器
    ├── ClientSdkGenerator.cs  # 主生成器
    └── Emitters/
        ├── ActionEmitter.cs   # Action 代码发射器
        ├── ListenerEmitter.cs # Listener 代码发射器
        └── GameCodeEmitter.cs # GameCode 代码发射器

CLI 命令参考

export 命令

t2f-proto export [options]

Options:
  -a, --assembly <assembly>  要导出的程序集路径 (必需)
  -o, --output <output>      输出目录路径 (必需)
  -c, --clean               是否清理旧文件 [default: true]
  --all                     导出所有资源 [default: false]

sdk 命令

t2f-proto sdk [options]

Options:
  -a, --assembly <assembly>          服务器程序集路径 (必需)
  -o, --output <output>              输出目录路径 (必需)
  -n, --namespace <namespace>        客户端代码命名空间 [default: Game.Gen]
  -p, --proto-namespace <namespace>  Proto 类命名空间 [default: Game.Gen.Proto]
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on T2FGame.Tools:

Package Downloads
T2FGame.Samples.ProtoExport

A high-performance game server framework

T2FGame.Samples.ClientSdk

A high-performance game server framework

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.9 448 12/11/2025
1.0.8 436 12/11/2025
1.0.7 437 12/11/2025
1.0.6 441 12/11/2025
1.0.5 453 12/10/2025
1.0.4 454 12/10/2025
1.0.3 454 12/9/2025
1.0.2 368 12/8/2025
0.0.1 360 12/8/2025