/// <summary> /// Calls a remote function without payload, expecting a return value of a specific type /// </summary> /// <typeparam name="R">The type of the return value of the called function</typeparam> /// <param name="target">The target port to send the message to</param> /// <param name="name">The name of the remote function</param> /// <param name="payload">The payload to pass to the function</param> /// <param name="timeout">The amount of time, in seconds, to wait for a response</param> /// <param name="callback">The callback to call upon receiving a response</param> /// <param name="error">The callback to call upon encountering errors</param> public void RPC <R>(string target, string name, float timeout, UnityAction <R> callback, UnityAction <Exception> error) { try { var message = IMCMessage.CreateRequest(this.name, name); SendIMCMessage( target, message, timeout, (msg) => { callback?.Invoke(msg.ParsePayload <R>()); }, () => { error.Invoke(TimeoutException.Instance); }); } catch (Exception ex) { error?.Invoke(ex); } }
/// <summary> /// Calls a remote function using the given payload, expecting no return value /// </summary> /// <typeparam name="P">The type of the payload to pass to the function</typeparam> /// <param name="target">The target port to send the message to</param> /// <param name="name">The name of the remote function</param> /// <param name="payload">The payload to pass to the function</param> /// <param name="timeout">The amount of time, in seconds, to wait for a response</param> /// <param name="callback">The callback to call upon receiving a response</param> /// <param name="error">The callback to call upon encountering errors public void RPC <P>(string target, string name, P payload, float timeout, UnityAction callback, UnityAction <Exception> error) { try { var message = IMCMessage.CreateRequest(this.name, name, JsonConvert.SerializeObject(payload)); SendIMCMessage( target, message, timeout, (msg) => { callback?.Invoke(); }, () => { error.Invoke(TimeoutException.Instance); }); } catch (Exception ex) { error?.Invoke(ex); } }