1。添加 频道 中心组件 (增加 申请, 移除 等 功能)

This commit is contained in:
SnowShow 2025-04-16 11:32:16 +08:00
parent fe97e4ee3f
commit 5d0f1791a5
5 changed files with 72 additions and 1 deletions

View File

@ -0,0 +1,8 @@

using Fantasy.Entitas;
public class ChatChannel : Entity
{
public readonly HashSet<EntityReference<ChatUnit>> ChatUnits = new HashSet<EntityReference<ChatUnit>>();
}

View File

@ -0,0 +1,8 @@

using Fantasy.Entitas;
public class ChatChannelCenterComponent : Entity
{
public Dictionary<long,ChatChannel> ChatChannels = new Dictionary<long, ChatChannel>();
}

View File

@ -0,0 +1,46 @@
using Fantasy.Entitas;
using Fantasy.Entitas.Interface;
namespace Hotfix;
public class ChatChannelCenterComponentDestroySystem : DestroySystem<ChatChannelCenterComponent>
{
protected override void Destroy(ChatChannelCenterComponent self)
{
foreach (var channel in self.ChatChannels.Values.ToArray())
{
channel.Dispose();
}
self.ChatChannels.Clear();
}
}
public static class ChatChannelCenterComponentSystem
{
public static ChatChannel Apply(this ChatChannelCenterComponent self, long chatChannelId)
{
if (self.ChatChannels.TryGetValue(chatChannelId, out var channel))
{
return channel;
}
channel = Entity.Create<ChatChannel>(self.Scene,chatChannelId,true,true);
return channel;
}
public static bool TryGetChannel(this ChatChannelCenterComponent self, long chatChannelId, out ChatChannel channel)
{
return self.ChatChannels.TryGetValue(chatChannelId, out channel);
}
public static bool RemoveChannel(this ChatChannelCenterComponent self, long chatChannelId)
{
if (!self.ChatChannels.Remove(chatChannelId, out var channel))
{
return false;
}
channel.Dispose();
return true;
}
}

View File

@ -0,0 +1,9 @@
namespace Hotfix;
public class ChatChannelSystem
{
}

View File

@ -6,7 +6,7 @@ public class ChatComponentDestroySystem : DestroySystem<ChatComponent>
{
protected override void Destroy(ChatComponent self)
{
foreach (var chatUnit in self.ChatUnits.Values)
foreach (var chatUnit in self.ChatUnits.Values.ToArray())
{
chatUnit.Dispose();
}