IDistributed/IAsyncSybscriber for TCP/UDP on Unity
slimshader opened this issue · 1 comments
slimshader commented
Hi,
is this code correct (similar versionb is for the TCP):
public static ReturnType AddMessagePipeUdpInterprocess(this IServiceCollection services, string host, int port, Action<MessagePipeInterprocessUdpOptions> configure)
{
var options = new MessagePipeInterprocessUdpOptions(host, port);
configure(options);
services.AddSingleton(options);
services.Add(typeof(UdpWorker), options.InstanceLifetime);
#if !UNITY_2018_3_OR_NEWER
services.Add(typeof(IDistributedPublisher<,>), typeof(UdpDistributedPublisher<,>), options.InstanceLifetime);
services.Add(typeof(IDistributedSubscriber<,>), typeof(UdpDistributedSubscriber<,>), options.InstanceLifetime);
return services;
#else
AddAsyncMessageBroker<IInterprocessKey, IInterprocessValue>(services, options);
return options;
#endif
}
it seems it only registers IDistributedPub.Sub for older versions of Unity and IAsyncPub/Sub for newer ones
hadashiA commented
#if !UNITY_2018_3_OR_NEWER
This branch is true in non-Unity environments. (such as .NET runtime)
( 2018_3 is used because it is below the supported version.
Please see the Unity section of the README.
https://github.com/Cysharp/MessagePipe?tab=readme-ov-file#unity
Unity version does not have open generics support(for IL2CPP) and does not support auto registration. Therefore, all required types need to be manually registered.
- In Untiy environment, services.Add<IDistributedPublisher<YourKey, YourMessage>>() must be explicit.
- The difference is that in a non-Unity environment this is not required.