mirror of
https://github.com/NuclearPowered/Reactor.git
synced 2026-10-19 15:51:54 +00:00
CustomRpc SendTo
This commit is contained in:
4 files changed
+15
-4
No files matched your search
@@ -35,10 +35,11 @@ namespace Reactor.Example
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.F3))
|
||||
if (Input.GetKeyDown(KeyCode.F3) && AmongUsClient.Instance && PlayerControl.LocalPlayer)
|
||||
{
|
||||
Plugin.Log.LogWarning("Sending example rpc");
|
||||
PlayerControl.LocalPlayer.Send<ExampleRpc>(new ExampleRpc.Data("Cześć :)"));
|
||||
PlayerControl.LocalPlayer.SendTo<ExampleRpc>(AmongUsClient.Instance.HostId, new ExampleRpc.Data("host :O"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Reactor.Example
|
||||
}
|
||||
}
|
||||
|
||||
public override RpcLocalHandling LocalHandling => RpcLocalHandling.Before;
|
||||
public override RpcLocalHandling LocalHandling => RpcLocalHandling.None;
|
||||
|
||||
public override void Write(MessageWriter writer, Data data)
|
||||
{
|
||||
|
||||
@@ -126,7 +126,12 @@ namespace Reactor
|
||||
UnsafeSend(netObject, List.Single(x => x.GetType() == typeof(TCustomRpc)), data, immediately);
|
||||
}
|
||||
|
||||
public void UnsafeSend(InnerNetObject netObject, UnsafeCustomRpc customRpc, object data, bool immediately = false)
|
||||
public void SendTo<TCustomRpc>(InnerNetObject netObject, int targetId, object data)
|
||||
{
|
||||
UnsafeSend(netObject, List.Single(x => x.GetType() == typeof(TCustomRpc)), data, true, targetId);
|
||||
}
|
||||
|
||||
public void UnsafeSend(InnerNetObject netObject, UnsafeCustomRpc customRpc, object data, bool immediately = false, int targetClientId = -1)
|
||||
{
|
||||
if (netObject == null) throw new ArgumentNullException(nameof(netObject));
|
||||
if (customRpc == null) throw new ArgumentNullException(nameof(customRpc));
|
||||
@@ -145,7 +150,7 @@ namespace Reactor
|
||||
var writer = immediately switch
|
||||
{
|
||||
false => AmongUsClient.Instance.StartRpc(netObject.NetId, CallId, SendOption.Reliable),
|
||||
true => AmongUsClient.Instance.StartRpcImmediately(netObject.NetId, CallId, SendOption.Reliable, -1)
|
||||
true => AmongUsClient.Instance.StartRpcImmediately(netObject.NetId, CallId, SendOption.Reliable, targetClientId)
|
||||
};
|
||||
|
||||
if (PluginIdMap.TryGetValue(customRpc.PluginId, out var pluginId))
|
||||
|
||||
@@ -134,5 +134,10 @@ namespace Reactor.Extensions
|
||||
{
|
||||
PluginSingleton<ReactorPlugin>.Instance.CustomRpcManager.Send<TCustomRpc>(netObject, data, immediately);
|
||||
}
|
||||
|
||||
public static void SendTo<TCustomRpc>(this InnerNetObject netObject, int targetId, object data)
|
||||
{
|
||||
PluginSingleton<ReactorPlugin>.Instance.CustomRpcManager.SendTo<TCustomRpc>(netObject, targetId, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user