金庆的专栏

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  423 随笔 :: 0 文章 :: 454 评论 :: 0 Trackbacks
手机运行 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" });
* 完整代码见:https://gitee.com/jinq0123/unity-grpc-sample
* 最后打包安装到手机测试通过
posted on 2018-08-12 12:24 金庆 阅读(947) 评论(0)  编辑 收藏 引用 所属分类: 2. 网游开发

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理