diff --git a/Runtime/Network/Base/MessageHandlerAttribute.cs b/Runtime/Network/Base/MessageHandlerAttribute.cs
index e6cda46..4700edc 100644
--- a/Runtime/Network/Base/MessageHandlerAttribute.cs
+++ b/Runtime/Network/Base/MessageHandlerAttribute.cs
@@ -20,6 +20,8 @@ public class MessageHandlerAttribute : Attribute
private MethodInfo _invokeMethod;
private IMessageHandler _messageHandler;
+ private MessageObject _messageObject;
+
///
/// 网络消息处理器
///
@@ -42,8 +44,17 @@ public MessageHandlerAttribute(Type message, string invokeMethodName)
MessageType = message;
}
+
+ ///
+ /// 设置消息对象
+ ///
+ ///
+ public void SetMessageObject(MessageObject messageObject)
+ {
+ _messageObject = messageObject;
+ }
- internal void Invoke(MessageObject message)
+ internal void Invoke()
{
if (_invokeMethod == null)
{
@@ -52,11 +63,11 @@ internal void Invoke(MessageObject message)
if (_invokeMethod.IsStatic)
{
- _invokeMethod?.Invoke(null, new object[] { message });
+ _invokeMethod?.Invoke(null, new object[] { _messageObject });
}
else
{
- _invokeMethod?.Invoke(_messageHandler, new object[] { message });
+ _invokeMethod?.Invoke(_messageHandler, new object[] { _messageObject });
}
}
diff --git a/Runtime/Network/Network/NetworkManager.NetworkChannelBase.cs b/Runtime/Network/Network/NetworkManager.NetworkChannelBase.cs
index 0a8f6ec..2ebfec4 100644
--- a/Runtime/Network/Network/NetworkManager.NetworkChannelBase.cs
+++ b/Runtime/Network/Network/NetworkManager.NetworkChannelBase.cs
@@ -74,7 +74,7 @@ protected bool PActive
public Action NetworkChannelMissHeartBeat;
public Action NetworkChannelError;
public Action NetworkChannelCustomError;
-
+ private Queue m_ExecutionQueue = new Queue();
///
/// 初始化网络频道基类的新实例。
@@ -263,6 +263,13 @@ public virtual void Update(float elapseSeconds, float realElapseSeconds)
ProcessHeartBeat(realElapseSeconds);
PRpcState.Update(elapseSeconds, realElapseSeconds);
+ lock (m_ExecutionQueue)
+ {
+ while (m_ExecutionQueue.Count > 0)
+ {
+ m_ExecutionQueue.Dequeue()?.Invoke();
+ }
+ }
}
///
@@ -711,7 +718,11 @@ protected void InvokeMessageHandler(MessageObject messageObject)
{
try
{
- handler.Invoke(messageObject);
+ lock (m_ExecutionQueue)
+ {
+ handler.SetMessageObject(messageObject);
+ m_ExecutionQueue.Enqueue(handler);
+ }
}
catch (Exception e)
{