手機運行 Unity Grpc
(金慶的專欄 2018.8)
* 安裝 Unit2018, 支持 .NET 4.x
* 創(chuàng)建一個項目,開啟 .NET 4.x
Edit->Project Settings->Player->Other Settings
->Configuration->Script Runtime Version->.Net 4.x Equivalent
* 從 https://packages.grpc.io/ 的 Daily Builds 下載最新的
grpc-protoc_windows_x86-VERSION.zip
grpc_unity_package.VERSION.zip
* grpc_unity_package.VERSION.zip
解壓到 Assets 目錄下
* 從 github grpc 復(fù)制 examples/protos/helloworld.proto 為 Assets/protos/helloworld.proto
* 創(chuàng)建 Assets/Scripts/Greeter/, 并在該目錄下運行
protoc.exe -I../../../protos --csharp_out=. ../../../protos/helloworld.proto --grpc_out=. --plugin=protoc-gen-grpc=grpc_csharp_plugin.exe
(金慶的專欄 2018.8)
* 安裝 Unit2018, 支持 .NET 4.x
* 創(chuàng)建一個項目,開啟 .NET 4.x
Edit->Project Settings->Player->Other Settings
->Configuration->Script Runtime Version->.Net 4.x Equivalent
* 從 https://packages.grpc.io/ 的 Daily Builds 下載最新的
grpc-protoc_windows_x86-VERSION.zip
grpc_unity_package.VERSION.zip
* grpc_unity_package.VERSION.zip
解壓到 Assets 目錄下
* 從 github grpc 復(fù)制 examples/protos/helloworld.proto 為 Assets/protos/helloworld.proto
* 創(chuàng)建 Assets/Scripts/Greeter/, 并在該目錄下運行
protoc.exe -I../../../protos --csharp_out=. ../../../protos/helloworld.proto --grpc_out=. --plugin=protoc-gen-grpc=grpc_csharp_plugin.exe
+ 需要先從 grpc-protoc_windows_x86-VERSION.zip 解壓 protoc.exe,grpc_csharp_plugin.exe
+ 生成 Helloworld.cs HelloworldGrpc.cs
+ 生成 Helloworld.cs HelloworldGrpc.cs
* 客戶端代碼
+ 創(chuàng)建Channel連接服務(wù)器
channel = new Channel("127.0.0.1:50051", ChannelCredentials.Insecure);
+ 創(chuàng)建客戶端并發(fā)出請求
var client = new Greeter.GreeterClient(channel);
HelloReply reply = client.SayHello(new HelloRequest { Name = "Jin Qing" });
* 完整代碼見:https://gitee.com/jinq0123/unity-grpc-sample
* 最后打包安裝到手機測試通過
+ 創(chuàng)建Channel連接服務(wù)器
channel = new Channel("127.0.0.1:50051", ChannelCredentials.Insecure);
+ 創(chuàng)建客戶端并發(fā)出請求
var client = new Greeter.GreeterClient(channel);
HelloReply reply = client.SayHello(new HelloRequest { Name = "Jin Qing" });
* 完整代碼見:https://gitee.com/jinq0123/unity-grpc-sample
* 最后打包安裝到手機測試通過