using Fantasy; using Fantasy.Entitas.Interface; namespace Hotfix; public class ChatComponentDestroySystem : DestroySystem { protected override void Destroy(ChatComponent self) { foreach (var chatUnit in self.ChatUnits.Values.ToArray()) { chatUnit.Dispose(); } self.ChatUnits.Clear(); } } public static class ChatComponentSystem { public static void AddChatUnit(this ChatComponent self,ChatUnit chatUnit) { if (self.ChatUnits.ContainsKey(chatUnit.RuntimeId)) { Log.Debug($" chat unit already added: {chatUnit.AccountId} {chatUnit.GameName} "); return; } self.ChatUnits.Add(chatUnit.RuntimeId, chatUnit); } public static void RemoveChatUnit(this ChatComponent self, long accountId) { if (!self.ChatUnits.Remove(accountId,out var chatUnit)) { Log.Debug($" chat unit is not exist: {accountId} "); return; } chatUnit.Dispose(); } }