/// <summary> /// Sends request message with optional data. /// </summary> /// <param name="id">The message id (identifying target).</param> /// <param name="request">The data attached to the message.</param> /// <returns>Response message from the target.</returns> /// <remarks> /// Message format: /// { /// "id": MESSAGE_TARGET_ID, // <paramref name="id" /> /// "type": SERIALIZED_TYPE, // <paramref name="request.Type" /> /// "data": SERIALIZED_DATA, // <paramref name="request" /> /// "uuid": UNIQUE_REQUEST_IDENTIFIER // Exists only when <paramref name="onResponse" /> callback is provided /// } /// /// Message is automatically prefixed with <see cref="UnityMessageManager.MessagePrefix" /> /// constant to distinguish it from unformatted messages. /// </remarks> public static UniTask <TResponse> SendAsync <TMessageType, TResponse>(string id, IUnityRequest <TMessageType> request, CancellationToken cancellationToken = default(CancellationToken)) where TMessageType : Enum => UnityMessageManager.instance.SendRequestAsync <TResponse>(id, (int)(object)request.Type(), request, cancellationToken);
public static UniTask <TResponse> InjectAsync <TRequestType, TResponse>(string id, IUnityRequest <TRequestType, TResponse> data, CancellationToken cancellationToken = default(CancellationToken)) where TRequestType : Enum => UnityMessageManager.instance.InjectInternalAsync <TResponse>(id, GetNextUUID(), (int)(object)data.Type(), data, cancellationToken);