インディゲーム開発者向けオールインワンソリューション · インディ開発者の夢を支援
📖 ドキュメント • 💬 QQグループ: 467608841
🌐 言語: English | 简体中文 | 繁體中文 | 日本語 | 한국어
言語別エクスポートの Proto プロトコルコード生成ツールです。C#、TypeScript に対応、C++ と Lua は開発中です。
linux/amd64 および linux/arm64 用の Docker イメージが提供されています。
Docker Hub
docker pull gameframex/gameframex-tools:latestGitHub Container Registry (GHCR)
docker pull ghcr.io/gameframex/gameframex.tools:latest使用例
docker run --rm \
-v /path/to/protos:/protos \
-v /path/to/output:/output \
gameframex/gameframex-tools:latest \
--mode csharp --isServer true --usingStatements "using System|using ProtoBuf|using System.Collections.Generic|using GameFrameX.NetWork.Abstractions|using GameFrameX.NetWork.Messages" --isGenerateDescription true --inputPath /protos --outputPath /output --namespaceName GameFrameX.Proto.Proto本ツールは .proto ファイルの書式について特定の要件があります。正しくコードを生成するために、以下のルールに従ってください。
syntax = "proto3"; // 必須:proto3 のみサポート
package Basic;
option module = 10; // 必須:モジュール ID の定義
// ハートビートリクエスト
message ReqHeartBeat
{
int64 Timestamp = 1; // タイムスタンプ
}- リクエストメッセージ:
Reqで始まる必要があります(例:ReqLogin、ReqHeartBeat) - レスポンスメッセージ:
Respで始まる必要があります(例:RespLogin) - 通知メッセージ:
Notifyで始まる必要があります(例:NotifyBagInfoChanged) - メッセージ名、フィールド名、enum名、enum値はすべて UpperCamelCase(アッパーキャメルケース)を使用
option module = <id>; でモジュール ID を定義します:
| ID 範囲 | 用途 |
|---|---|
0 ~ 32767 |
クライアント-サーバー間通信 |
-32768 ~ -1 |
サーバー-サーバー間通信 |
- メッセージのフィールド番号は 800 未満である必要があります(800 以上はシステム予約であり、パースエラーの原因になります)
ErrorCodeはレスポンスメッセージの予約フィールド名です。手動で定義しないでください。Respメッセージには自動的にErrorCodeフィールドが生成されます
- ネスト型非対応:message 内部での
message、enum、その他カスタム型のネストはサポートされていません - RPC 定義非対応:proto ファイル内での RPC サービス定義はサポートされていません
- proto3 のみ対応:
syntax = "proto3";の宣言が必須です。proto2 はサポートされていません
- message と enum 定義の上にコメントを追加:
// ハートビートリクエスト
message ReqHeartBeat
{
int64 Timestamp = 1;
}- フィールド行の末尾にインラインコメントを追加:
// プレイヤー情報
message PlayerInfo
{
int64 Id = 1; // プレイヤーID
string Name = 2; // プレイヤー名
uint32 Level = 3; // プレイヤーレベル
int32 State = 4; // プレイヤー状態
}完全なプロトコル仕様については 通信プロトコル仕様 と 注意事項 のドキュメントを参照してください。
TestProtos/ ディレクトリには、主要なパターンを網羅したサンプル proto ファイルが含まれています:
| ファイル | パターン | モジュール ID |
|---|---|---|
heartbeat.proto |
基本的な Req/Resp | 1(クライアント-サーバー) |
player.proto |
Req/Resp/Notify + enum + map | 2(クライアント-サーバー) |
bag.proto |
enum + repeated + map + Notify | 3(クライアント-サーバー) |
admin-s.proto |
サーバー専用プロトコル(-s 接尾辞) |
99(クライアント-サーバー) |
server-internal-s.proto |
サーバー間通信(負のモジュール ID) | -1(サーバー-サーバー) |
| パラメータ | 必須 | デフォルト | 説明 |
|---|---|---|---|
--mode |
はい | - | 言語モード:csharp、typescript、cpp、lua |
--inputPath |
はい | - | .proto ファイルのディレクトリパス |
--outputPath |
はい | - | 生成ファイルの出力パス |
--namespaceName |
いいえ | "" |
生成コードの名前空間(C# のみ有効、TypeScript では無視) |
--isGenerateErrorCode |
いいえ | true |
レスポンスメッセージに ErrorCode フィールドを自動生成するか |
--requireComments |
いいえ | none |
コメント検証レベル:none(検証なし)、container(message/enum にコメント必須)、member(フィールド/enum メンバーにコメント必須)、all(すべて) |
| パラメータ | 必須 | デフォルト | 説明 |
|---|---|---|---|
--usingStatements |
いいえ | "" |
using 文を | で区切って指定(例:"using System|using ProtoBuf|using System.Collections.Generic") |
--isGenerateDescription |
いいえ | false |
[System.ComponentModel.Description] 属性を生成するか |
--isServer |
いいえ | false |
サーバー専用 proto ファイル(-s または _s で終わるファイル)を含めるか |
| パラメータ | 必須 | デフォルト | 説明 |
|---|---|---|---|
--importPath |
いいえ | "../network/" |
生成される import 文のパスプレフィックス |
--isGenerateDescription |
いいえ | false |
JSDoc スタイルのコメントを生成するか |
| パラメータ | 必須 | デフォルト | 説明 |
|---|---|---|---|
--isGenerateErrorCodeExcelFile |
いいえ | true |
エラーコード Excel ファイルを生成するか |
--errorCodeExcelFilePath |
いいえ | "" |
エラーコード Excel ファイルのカスタムパス |
| モード | 出力言語 | ファイル拡張子 | 説明 |
|---|---|---|---|
csharp |
C# | .cs |
Server、Unity、Godot、Stride、Flax などに対応 |
typescript |
TypeScript | .ts |
LayaAir、Cocos Creator、Phaser などに対応 |
cpp |
C++ | .h |
Unreal Engine などに対応 |
lua |
Lua | .lua |
Defold、Solar2D、Dora SSR などに対応 |
go |
Go | .go |
Go ゲームサーバーなどに対応 |
[ProtoContract] / [ProtoMember] 属性付きの C# コードを生成します。すべての動作は CLI パラメータで制御され、エンジン固有のハードコードはありません。
サーバー用の using 文、[Description] 属性付きのコードを生成し、サーバー専用 proto ファイルを含めます。
ローカル実行:
dotnet ProtoExport.dll \
--mode csharp \
--isServer true \
--usingStatements "using System|using ProtoBuf|using System.Collections.Generic|using GameFrameX.NetWork.Abstractions|using GameFrameX.NetWork.Messages" \
--isGenerateDescription true \
--inputPath ./../../../../../Protobuf \
--outputPath ./../../../../../Server/GameFrameX.Proto/Proto \
--namespaceName GameFrameX.Proto.Proto \
--isGenerateErrorCode trueDocker 実行:
docker run --rm \
-v ./Protobuf:/protos \
-v ./Server/GameFrameX.Proto/Proto:/output \
gameframex/gameframex-tools:latest \
--mode csharp --isServer true \
--usingStatements "using System|using ProtoBuf|using System.Collections.Generic|using GameFrameX.NetWork.Abstractions|using GameFrameX.NetWork.Messages" \
--isGenerateDescription true \
--inputPath /protos --outputPath /output --namespaceName GameFrameX.Proto.ProtoUnity 用の using 文付きコードを生成し、サーバー専用 proto ファイルは自動的にスキップされます。
dotnet ProtoExport.dll \
--mode csharp \
--usingStatements "using System|using ProtoBuf|using System.Collections.Generic|using GameFrameX.Network.Runtime" \
--inputPath ./../../../../../Protobuf \
--outputPath ./../../../../../Unity/Assets/Hotfix/Proto \
--namespaceName Hotfix.Proto \
--isGenerateErrorCode trueUnity と同様ですが、Godot 固有の名前空間を使用します。
dotnet ProtoExport.dll \
--mode csharp \
--usingStatements "using System|using ProtoBuf|using System.Collections.Generic|using GameFrameX.Network.Runtime" \
--inputPath ./../../../../../Protobuf \
--outputPath ./../../../../../Godot/Proto \
--namespaceName Proto \
--isGenerateErrorCode trueexport namespace、export class、export enum を含む .ts ファイルと、集約ファイル ProtoMessageRegister.ts を生成します。サーバー専用 proto ファイルは自動的にスキップされます。
dotnet ProtoExport.dll \
--mode typescript \
--inputPath ./../../../../../Protobuf \
--outputPath ./../../../../../Laya/src/gameframex/protobuf \
--isGenerateErrorCode truedotnet ProtoExport.dll \
--mode typescript \
--importPath "./lib/network/" \
--inputPath ./../../../../../Protobuf \
--outputPath ./../../../../../CocosCreator/assets/scripts/protobuf \
--isGenerateErrorCode trueDocker 実行:
docker run --rm \
-v ./Protobuf:/protos \
-v ./Laya/src/gameframex/protobuf:/output \
gameframex/gameframex-tools:latest \
--mode typescript --inputPath /protos --outputPath /output#pragma once、名前空間、enum class、クラス定義を含む C++ ヘッダファイルを生成します。MessageObject を継承するクラスには MESSAGE_ID と Clear() メソッドが含まれます。
dotnet ProtoExport.dll \
--mode cpp \
--usingStatements "#include <cstdint>|#include <string>|#include <vector>|#include <unordered_map>" \
--inputPath ./../../../../../Protobuf \
--outputPath ./../../../../../Unreal/Source/Proto \
--namespaceName GameFrameX.ProtoLuaDoc(EmmyLua)スタイルの型アノテーションとモジュールベースのメッセージ定義を含む .lua ファイルを生成します。集約ファイル ProtoMessageRegister.lua も生成されます。
dotnet ProtoExport.dll \
--mode lua \
--importPath "./network/" \
--inputPath ./../../../../../Protobuf \
--outputPath ./../../../../../Defold/scripts/protobufDocker 実行:
docker run --rm \
-v ./Protobuf:/protos \
-v ./Defold/scripts/protobuf:/output \
gameframex/gameframex-tools:latest \
--mode lua --importPath "./network/" --inputPath /protos --outputPath /outputprotobuf タグ付きの Go struct 定義、enum 型定義、集約ファイル message_register.go を生成します。--namespaceName は Go パッケージ名として使用されます(ドット区切りの場合は最後のセグメント)。
dotnet ProtoExport.dll \
--mode go \
--usingStatements "google.golang.org/protobuf/runtime/protoimpl" \
--inputPath ./../../../../../Protobuf \
--outputPath ./../../../../../GoServer/proto \
--namespaceName protoDocker 実行:
docker run --rm \
-v ./Protobuf:/protos \
-v ./GoServer/proto:/output \
gameframex/gameframex-tools:latest \
--mode go --inputPath /protos --outputPath /output --namespaceName protoProtobuf/ ディレクトリにプリセットのエクスポートスクリプトが用意されています:
| スクリプト | 説明 |
|---|---|
Proto2CsExport_Server.sh/.bat |
C# サーバー用コードのエクスポート |
Proto2CsExport_Client.sh/.bat |
C# Unity クライアント用コードのエクスポート |
Proto2TsExport.sh/.bat |
TypeScript コードのエクスポート |
Proto2CppExport.sh/.bat |
C++ コードのエクスポート |
Proto2LuaExport.sh/.bat |
Lua コードのエクスポート |
Proto2GoExport.sh/.bat |
Go コードのエクスポート |
Docker 使用時のパスマッピングは以下の通りです:
-v <ホストパス>:<コンテナパス>でホストのディレクトリをコンテナにマウントします--inputPathと--outputPathにはコンテナ内パス(例:/protos、/output)を指定します(ホストパスではありません)
# 例:ホスト ./my-protos -> コンテナ /protos
docker run --rm \
-v $(pwd)/my-protos:/protos \
-v $(pwd)/my-output:/output \
gameframex/gameframex-tools:latest \
--mode csharp --isServer true \
--usingStatements "using System|using ProtoBuf|using System.Collections.Generic|using GameFrameX.NetWork.Abstractions|using GameFrameX.NetWork.Messages" \
--isGenerateDescription true \
--inputPath /protos --outputPath /output --namespaceName GameFrameX.Proto.Proto