11using System ;
2+ using System . Collections . Generic ;
23using System . Reflection ;
4+ using GameFrameX . Runtime ;
35
46namespace GameFrameX . Network . Runtime
57{
@@ -32,9 +34,9 @@ public class MessageHandlerAttribute : Attribute
3234 private IMessageHandler m_MessageHandler ;
3335
3436 /// <summary>
35- /// 消息对象
37+ /// 消息处理对象队列
3638 /// </summary>
37- private MessageObject m_MessageObject ;
39+ private readonly Queue < MessageObject > m_MessageObjects = new Queue < MessageObject > ( ) ;
3840
3941 /// <summary>
4042 /// 网络消息处理器
@@ -66,7 +68,7 @@ public MessageHandlerAttribute(Type message, string invokeMethodName)
6668 public void SetMessageObject ( MessageObject messageObject )
6769 {
6870 GameFrameworkGuard . NotNull ( messageObject , nameof ( messageObject ) ) ;
69- m_MessageObject = messageObject ;
71+ m_MessageObjects . Enqueue ( messageObject ) ;
7072 }
7173
7274 internal void Invoke ( )
@@ -76,13 +78,21 @@ internal void Invoke()
7678 throw new ArgumentNullException ( nameof ( m_InvokeMethod ) , $ "未找到方法:{ m_InvokeMethodName } .请确认是否注册成功") ;
7779 }
7880
81+ if ( m_MessageObjects . Count <= 0 )
82+ {
83+ Log . Warning ( $ "没有消息对象转发到方法:{ m_InvokeMethodName } ") ;
84+ return ;
85+ }
86+
87+ var messageObject = m_MessageObjects . Dequeue ( ) ;
88+
7989 if ( m_InvokeMethod . IsStatic )
8090 {
81- m_InvokeMethod ? . Invoke ( null , new object [ ] { m_MessageObject } ) ;
91+ m_InvokeMethod ? . Invoke ( null , new object [ ] { messageObject } ) ;
8292 }
8393 else
8494 {
85- m_InvokeMethod ? . Invoke ( m_MessageHandler , new object [ ] { m_MessageObject } ) ;
95+ m_InvokeMethod ? . Invoke ( m_MessageHandler , new object [ ] { messageObject } ) ;
8696 }
8797 }
8898
0 commit comments