private void DoCall(Node Target) { switch (Type) { case TypeOfCall.RPC: MethodInfo methodInfo = MDStatics.GetMethodInfo(Target, Convert.ToInt32(Name)); if (methodInfo == null) { MDLog.Fatal(LOG_CAT, $"Could not find method {Target.GetType().ToString()}#{Name}"); return; } object[] convertedParams = MDStatics.ConvertParametersBackToObject(methodInfo, Parameters); MDStatics.GetReplicator().RpcSenderId = SenderPeerId; methodInfo.Invoke(Target, convertedParams); MDStatics.GetReplicator().RpcSenderId = -1; break; case TypeOfCall.RSET: MemberInfo memberInfo = MDStatics.GetMemberInfo(Target, Name); IMDDataConverter Converter = MDStatics.GetConverterForType(memberInfo.GetUnderlyingType()); object value = Converter.ConvertBackToObject(memberInfo.GetValue(Target), Parameters); MDLog.Trace(LOG_CAT, $"Setting {Name} on {Target.Name} to value {value}"); memberInfo.SetValue(Target, value); break; } }
/// <summary> /// Same as RsetUnreliable except it checks if the network is activate first /// </summary> /// <param name="PeerId">The peer to send to</param> /// <param name="Property">The property to set</param> /// <param name="Value">The value</param> public static void MDRsetUnreliableId(this Node Instance, int PeerId, string Property, object Value) { if (!MDStatics.IsNetworkActive() && !MDStatics.IsServer()) { return; } MDStatics.GetReplicator().SendClockedRset(PeerId, MDReliability.Unreliable, Instance, Property, Value); }
/// <summary> /// Same as Rset except it checks if the network is activate first /// </summary> /// <param name="Property">The property to set</param> /// <param name="Value">The value</param> public static void MDRset(this Node Instance, string Property, object Value) { if (!MDStatics.IsNetworkActive()) { return; } MDStatics.GetReplicator().SendClockedRset(-1, MDReliability.Reliable, Instance, Property, Value); }
/// <summary> /// Same as RpcUnreliableId except it checks if the network is activate first and takes game clock into account /// </summary> /// <param name="PeerId">The id of the peer to send to</param> /// <param name="Method">The method to call</param> /// <param name="Args">Arguments</param> public static void MDRpcUnreliableId(this Node Instance, int PeerId, string Method, params object[] Args) { if (!MDStatics.IsNetworkActive() && !MDStatics.IsServer()) { return; } // Send through replicator MDStatics.GetReplicator().SendClockedRpc(PeerId, MDReliability.Unreliable, Instance, Method, Args); }
// /// <summary> /// Same as Rpc except it checks if the network is activate first and takes game clock 1o account /// </summary> /// <param name="Method">The method to call</param> /// <param name="Args">Arguments</param> public static void MDRpc(this Node Instance, string Method, params object[] Args) { if (!MDStatics.IsNetworkActive()) { return; } // Send through replicator MDStatics.GetReplicator().SendClockedRpc(-1, MDReliability.Reliable, Instance, Method, Args); }
/// <summary> /// Get the sender ID of the current MDRpc call /// </summary> /// <returns>The sender ID or -1 if not inside an MDRpc call</returns> public static int MDGetRpcSenderId(this Node Instance) { return(MDStatics.GetReplicator().RpcSenderId); }