method caching for rpc, small fixes
parent
fcfff4690f
commit
3154fc5094
|
|
@ -6,12 +6,6 @@ using VelNet;
|
||||||
|
|
||||||
public class RPCTest : NetworkComponent
|
public class RPCTest : NetworkComponent
|
||||||
{
|
{
|
||||||
// Start is called before the first frame update
|
|
||||||
void Start()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update is called once per frame
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
if (Input.GetKeyDown(KeyCode.R))
|
if (Input.GetKeyDown(KeyCode.R))
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ namespace VelNet
|
||||||
protected bool IsMine => networkObject != null && networkObject.owner != null && networkObject.owner.isLocal;
|
protected bool IsMine => networkObject != null && networkObject.owner != null && networkObject.owner.isLocal;
|
||||||
protected VelNetPlayer Owner => networkObject != null ? networkObject.owner : null;
|
protected VelNetPlayer Owner => networkObject != null ? networkObject.owner : null;
|
||||||
|
|
||||||
|
private MethodInfo[] methodInfos;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// call this in child classes to send a message to other people
|
/// call this in child classes to send a message to other people
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -41,11 +43,16 @@ namespace VelNet
|
||||||
int length = reader.ReadInt32();
|
int length = reader.ReadInt32();
|
||||||
byte[] parameterData = reader.ReadBytes(length);
|
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));
|
if (methodInfos == null)
|
||||||
|
{
|
||||||
|
methodInfos = GetType().GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
|
||||||
|
Array.Sort(methodInfos, (m1, m2) => string.Compare(m1.Name, m2.Name, StringComparison.Ordinal));
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
mInfos[methodIndex].Invoke(this, length > 0 ? new object[] { parameterData } : Array.Empty<object>());
|
methodInfos[methodIndex].Invoke(this, length > 0 ? new object[] { parameterData } : Array.Empty<object>());
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
@ -79,9 +86,13 @@ namespace VelNet
|
||||||
using MemoryStream mem = new MemoryStream();
|
using MemoryStream mem = new MemoryStream();
|
||||||
using BinaryWriter writer = new BinaryWriter(mem);
|
using BinaryWriter writer = new BinaryWriter(mem);
|
||||||
|
|
||||||
MethodInfo[] mInfos = GetType().GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
|
if (methodInfos == null)
|
||||||
Array.Sort(mInfos, (m1, m2) => string.Compare(m1.Name, m2.Name, StringComparison.Ordinal));
|
{
|
||||||
int methodIndex = mInfos.ToList().FindIndex(m => m.Name == methodName);
|
methodInfos = GetType().GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
|
||||||
|
Array.Sort(methodInfos, (m1, m2) => string.Compare(m1.Name, m2.Name, StringComparison.Ordinal));
|
||||||
|
}
|
||||||
|
|
||||||
|
int methodIndex = methodInfos.ToList().FindIndex(m => m.Name == methodName);
|
||||||
switch (methodIndex)
|
switch (methodIndex)
|
||||||
{
|
{
|
||||||
case > 255:
|
case > 255:
|
||||||
|
|
|
||||||
|
|
@ -12,4 +12,4 @@ MonoBehaviour:
|
||||||
m_Script: {fileID: 0}
|
m_Script: {fileID: 0}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier: Unity.Rider.Editor:Packages.Rider.Editor:RiderScriptEditorPersistedState
|
m_EditorClassIdentifier: Unity.Rider.Editor:Packages.Rider.Editor:RiderScriptEditorPersistedState
|
||||||
lastWriteTicks: -8585461721809239573
|
lastWriteTicks: -8585461253992250955
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue