首先下载官方示例:
git clone https://github.com/grpc/grpc.git
打开examples\csharp\Helloworld\Greeter.sln,生成解决方案,运行GreeterServer
Greeter server listening on port 50051
Press any key to stop the server...
_
注意:这一步需要有安装.NET Core SDK 2.1及以上,使用Visual Studio Installer亦可
在Unity中配置(测试版本是2018.2.20f1)
1,创建空的Unity工程,在File -> Build Settings -> Player Settings中把Script Runtime Version设为 .NET 4.x
2,目前Grpc C#对Unity仍是实验性支持,只能在Daily Builds下载相应的运行库
3,将grpc_unity_package.VERSION.zip解压到Assets目录下
4,上一步GreeterClient项目生成的Greeter.dll和GreetClient.dll复制到Assets/Plugins目录下
5,新建脚本GrpcTest.cs挂在场景中任意GameObject,在Start()方法中添加代码,运行游戏
// Use this for initialization
void Start()
{
Channel channel = new Channel(&