About Unity using Protobuf

I recently learned the part of Scoket data transmission, and then saw some tools for data transmission Protobuf.
There are various introductions about Protobuf, and the more you look at it, the more confused you become.
The following is the information I have summarized about Protobuf.
There are many plug-in introductions about Protobuf on the Internet that are not actually a thing. There are two types of them: one is the native Protobuf native Protobuf link address,
and the other is a library based on native Protobuf protobuf -net. You can find the third-party library collection link address
from the third-party library link at the official address.

In addition to the above two, the projects that many people participate in may also contain some things that are similar to the above but not the same, and the differences are not caused by version differences.
You can refer to the following links:

protobuf3-for-Unity-and-ILRuntime

protobuf-net

The above is probably the reason why the tutorials marked with Protobuf are quite different.
The reference content for the reason is as follows: Using CSharp to write Google Protobuf plug-in

The role of Protobuf is no longer introduced here.
Regarding which version to use, the kind of document you read is easier to understand, just choose that one.
Here I briefly explain the use of native Protobuf.

1: Download the native csharpProtobuf source code from the link above.

2: Open the csharp/src/Google.Protobuf.sln file in the project directory.

insert image description hereGeneratedlls. Copy it into the project for use.

insert image description here
Or directly drag the source code into the project for use.

3: Prepare the compiler to compile the proto file into C# code.

One: The compiler can be downloaded directly from GitHub or you can choose to use the tool to generate it yourself. Download https://github.com/protocolbuffers/protobuf/releases from GitHub , download the corresponding protobuf package (such as protoc-3.15.6-win64.zip), and there is a corresponding protoc.exe compiler in the bin folder.
2: Generate protoc.exe by yourself.
1: Install Cmake https://cmake.org/
2: Configure the generated project, this operation will generate a project from Protobuf's cmake.
insert image description here3: Generate tools
OpenProject directly after generation.
insert image description here
After generation, you can get the following files.
insert image description here
Here you can generate c# code through the command line.

that's all.

Guess you like

Origin blog.csdn.net/qq_39860954/article/details/115251333