MyGit

4.2.0

Cysharp/MagicOnion

版本发布时间: 2021-04-02 14:18:51

Cysharp/MagicOnion最新发布版本:6.1.4(2024-07-17 15:51:31)

New Features

Unity: Introduce gRPC channel management integration #414

Wraps gRPC channels and provides a mechanism to manage them with Unity's lifecycle. This prevents your application and the Unity Editor from freezing by releasing channels and StreamingHub in one place.

The editor extension also provides the ability to display the communication status of channels.

Screen08

NOTE: The data rate is calculated only for the message body of methods, and does not include Headers, Trailers, or Keep-alive pings.

New APIs

MagicOnion.GrpcChannelx class

MagicOnion.Unity.GrpcChannelProviderHost class

MagicOnion.Unity.IGrpcChannelProvider interface

Usages

1. Prepare to use GrpcChannelx in your Unity project.

Before creating a channel in your application, you need to initialize the provider host to be managed.

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
public static void OnRuntimeInitialize()
{
    // Initialize gRPC channel provider when the application is loaded.
    GrpcChannelProviderHost.Initialize(new DefaultGrpcChannelProvider(new []
    {
        // send keepalive ping every 5 second, default is 2 hours
        new ChannelOption("grpc.keepalive_time_ms", 5000),
        // keepalive ping time out after 5 seconds, default is 20 seconds
        new ChannelOption("grpc.keepalive_timeout_ms", 5 * 1000),
    }));
}

GrpcChannelProviderHost will be created as DontDestroyOnLoad and keeps existing while the application is running. DO NOT destory it.

image

2. Use GrpcChannelx.FromTarget or GrpcChannelx.FromAddress to create a channel.

Use GrpcChannelx.FromTarget or GrpcChannelx.FromAddress to create a channel instead of new Channel(...).

var channel = GrpcChannelx.FromTarget(new GrpcChannelTarget("localhost", 12345, ChannelCredentials.Insecure));
// or
var channel = GrpcChannelx.FromAddress(new Uri("http://localhost:12345"));

3. Use the channel instead of Grpc.Core.Channel.

var channel = GrpcChannelx.FromAddress(new Uri("http://localhost:12345"));

var serviceClient = MagicOnionClient.Create<IGreeterService>(channel);
var hubClient = StreamingHubClient.ConnectAsync<IGreeterHub, IGreeterHubReceiver>(channel, this);

Extensions for Unity Editor (Editor Window & Inspector)

image

Improvements

Fixes

相关地址:原始地址 下载(tar) 下载(zip)

1、 MagicOnion.Client.Unity.unitypackage 161.44KB

2、 moc.4.2.0.zip 65.18MB

查看:2021-04-02发行的版本