内容简介:手机运行 Unity Grpc(金庆的专栏 2018.8)
手机运行 Unity Grpc
(金庆的专栏 2018.8)
- 安装 Unit2018, 支持 .NET 4.x
-
创建一个项目,开启 .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 复制 examples/protos/helloworld.proto 为 Assets/protos/helloworld.proto
-
创建 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
-
客户端代码
-
创建Channel连接服务器
channel = new Channel("127.0.0.1:50051", ChannelCredentials.Insecure); -
创建客户端并发出请求
var client = new Greeter.GreeterClient(channel); HelloReply reply = client.SayHello(new HelloRequest { Name = "Jin Qing" });
-
创建Channel连接服务器
- 完整代码见: https://gitee.com/jinq0123/unity-grpc-sample
- 最后打包安装到手机测试通过
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Learn Python 3 the Hard Way
Zed A. Shaw / Addison / 2017-7-7 / USD 30.74
You Will Learn Python 3! Zed Shaw has perfected the world’s best system for learning Python 3. Follow it and you will succeed—just like the millions of beginners Zed has taught to date! You bring t......一起来看看 《Learn Python 3 the Hard Way》 这本书的介绍吧!