Browse Source

广播消息只序列化一次消息

tanghai 3 years ago
parent
commit
1946bd65c2

+ 3 - 1
Codes/Hotfix/Server/Demo/Helper/MessageHelper.cs

@@ -1,6 +1,7 @@
 
 
 using System.Collections.Generic;
+using System.IO;
 
 namespace ET.Server
 {
@@ -23,9 +24,10 @@ namespace ET.Server
         public static void Broadcast(Unit unit, IActorMessage message)
         {
             Dictionary<long, AOIEntity> dict = unit.GetBeSeePlayers();
+            (ushort _, MemoryStream memoryStream) = MessageSerializeHelper.MessageToStream(message);
             foreach (AOIEntity u in dict.Values)
             {
-                SendToClient(u.Unit, message);
+                ActorMessageSenderComponent.Instance.Send(u.Unit.GetComponent<UnitGateComponent>().GateSessionActorId, memoryStream);
             }
         }
         

+ 1 - 1
Codes/Hotfix/Server/Module/Actor/ActorMessageSenderComponentSystem.cs

@@ -39,7 +39,7 @@ namespace ET.Server
             protected override void Destroy(ActorMessageSenderComponent self)
             {
                 ActorMessageSenderComponent.Instance = null;
-                TimerComponent.Instance.Remove(ref self.TimeoutCheckTimer);
+                TimerComponent.Instance?.Remove(ref self.TimeoutCheckTimer);
                 self.TimeoutCheckTimer = 0;
                 self.TimeoutActorMessageSenders.Clear();
             }