mirror of
https://github.com/NuclearPowered/Reactor.git
synced 2026-10-20 01:46:21 +00:00
Add an Example
This commit is contained in:
1 parent
eb7fce3350
commit
63fdde22c6
5 files changed
+23
-8
No files matched your search
@@ -2,6 +2,7 @@ namespace Reactor.Example
|
|||||||
{
|
{
|
||||||
public enum CustomRpcCalls : uint
|
public enum CustomRpcCalls : uint
|
||||||
{
|
{
|
||||||
Example
|
Example,
|
||||||
|
MethodRpcExample
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@ using BepInEx;
|
|||||||
using BepInEx.IL2CPP;
|
using BepInEx.IL2CPP;
|
||||||
using Reactor.Extensions;
|
using Reactor.Extensions;
|
||||||
using Reactor.Networking;
|
using Reactor.Networking;
|
||||||
|
using Reactor.Networking.MethodRpc;
|
||||||
using UnhollowerBaseLib.Attributes;
|
using UnhollowerBaseLib.Attributes;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@@ -43,7 +44,18 @@ namespace Reactor.Example
|
|||||||
Rpc<ExampleRpc>.Instance.SendTo(AmongUsClient.Instance.HostId, new ExampleRpc.Data($"SendTo: from {name} to host"));
|
Rpc<ExampleRpc>.Instance.SendTo(AmongUsClient.Instance.HostId, new ExampleRpc.Data($"SendTo: from {name} to host"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Input.GetKeyDown(KeyCode.F4) && AmongUsClient.Instance && PlayerControl.LocalPlayer)
|
||||||
|
{
|
||||||
|
RpcSay(PlayerControl.LocalPlayer, "Hello from method rpc");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MethodRpc((uint) CustomRpcCalls.MethodRpcExample)]
|
||||||
|
public static void RpcSay(PlayerControl sender, string text)
|
||||||
|
{
|
||||||
|
Logger<ExamplePlugin>.Info($"{sender.Data.PlayerName} said: {text}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,11 +11,11 @@ namespace Reactor.Networking.MethodRpc
|
|||||||
[AttributeUsage(AttributeTargets.Method)]
|
[AttributeUsage(AttributeTargets.Method)]
|
||||||
public class MethodRpcAttribute : Attribute
|
public class MethodRpcAttribute : Attribute
|
||||||
{
|
{
|
||||||
public byte id;
|
public uint id;
|
||||||
public SendOption option;
|
public SendOption option;
|
||||||
public RpcLocalHandling localHandling;
|
public RpcLocalHandling localHandling;
|
||||||
|
|
||||||
public MethodRpcAttribute( byte id, SendOption option = SendOption.Reliable, RpcLocalHandling localHandling = RpcLocalHandling.Before)
|
public MethodRpcAttribute( uint id, SendOption option = SendOption.Reliable, RpcLocalHandling localHandling = RpcLocalHandling.Before)
|
||||||
{
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.option = option;
|
this.option = option;
|
||||||
|
|||||||
@@ -28,9 +28,13 @@ namespace Reactor.Networking
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CustomMethodRpc methodRpc =
|
UnsafeCustomRpc methodRpc =
|
||||||
CustomMethodRpc.AllCustomMethodRpcs.FirstOrDefault(x => x.Method == originalMethod);
|
PluginSingleton<ReactorPlugin>.Instance.CustomRpcManager.List.FirstOrDefault(x => x is CustomMethodRpc && (x as CustomMethodRpc).Method == originalMethod);
|
||||||
typeof(CustomMethodRpc).GetMethod(nameof(CustomMethodRpc.Send))?.Invoke(methodRpc,new object[]{list});
|
if (methodRpc != null)
|
||||||
|
{
|
||||||
|
typeof(CustomMethodRpc).GetMethod(nameof(CustomMethodRpc.Send))?.Invoke((CustomMethodRpc)methodRpc, new object[] {list});
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Hazel;
|
using Hazel;
|
||||||
using InnerNet;
|
using InnerNet;
|
||||||
using Reactor;
|
|
||||||
using Reactor.Extensions;
|
using Reactor.Extensions;
|
||||||
using Reactor.Networking.MethodRpc;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Reactor.Networking
|
namespace Reactor.Networking
|
||||||
|
|||||||
Reference in new issue
Block a user