diff --git a/Runtime/NetworkComponent.cs b/Runtime/NetworkComponent.cs
index f1a9b31..70548e4 100644
--- a/Runtime/NetworkComponent.cs
+++ b/Runtime/NetworkComponent.cs
@@ -1,4 +1,8 @@
-using UnityEngine;
+using System;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+using UnityEngine;
namespace VelNet
{
@@ -13,20 +17,95 @@ namespace VelNet
///
protected void SendBytes(byte[] message, bool reliable = true)
{
- networkObject.SendBytes(this, message, reliable);
+ networkObject.SendBytes(this, false, message, reliable);
}
-
+
///
/// call this in child classes to send a message to other people
///
protected void SendBytesToGroup(string group, byte[] message, bool reliable = true)
{
- networkObject.SendBytesToGroup(this, group, message, reliable);
+ networkObject.SendBytesToGroup(this, false, group, message, reliable);
}
///
/// This is called by when messages are received for this component
///
public abstract void ReceiveBytes(byte[] message);
+
+ public void ReceiveRPC(byte[] message)
+ {
+ using MemoryStream mem = new MemoryStream(message);
+ using BinaryReader reader = new BinaryReader(mem);
+ byte methodIndex = reader.ReadByte();
+ int length = reader.ReadInt32();
+ byte[] parameterData = reader.ReadBytes(length);
+
+ MethodInfo[] mInfos = GetType().GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
+ Array.Sort(mInfos, (m1, m2) => string.Compare(m1.Name, m2.Name, StringComparison.Ordinal));
+ try
+ {
+ mInfos[methodIndex].Invoke(this, length > 0 ? new object[] { parameterData } : Array.Empty