聊天频道

This commit is contained in:
2025-08-08 09:13:09 +08:00
parent e1a4db89ae
commit 61496d4616
11 changed files with 190 additions and 6 deletions

View File

@@ -0,0 +1,51 @@
using Fantasy.Entitas;
namespace NB.Chat;
public static class ChatChannelCenterComponentSystem
{
/// <summary>
/// 申请
/// </summary>
/// <param name="self"></param>
/// <param name="channelId"></param>
/// <returns></returns>
public static ChatChannelComponent Apply(this ChatChannelCenterComponent self, long channelId)
{
if (self.Channels.TryGetValue(channelId, out var channel))
{
return channel;
}
channel = Entity.Create<ChatChannelComponent>(self.Scene, channelId, true, true);
self.Channels.Add(channelId, channel);
return channel;
}
/// <summary>
/// 获取
/// </summary>
/// <param name="self"></param>
/// <param name="channelId"></param>
/// <param name="channel"></param>
/// <returns></returns>
public static bool TryGet(this ChatChannelCenterComponent self, long channelId, out ChatChannelComponent? channel)
{
return self.Channels.TryGetValue(channelId, out channel);
}
/// <summary>
/// 解散
/// </summary>
/// <param name="self"></param>
/// <param name="channelId"></param>
public static void Disband(this ChatChannelCenterComponent self, long channelId)
{
if (self.Channels.Remove(channelId, out var channel))
{
return;
}
channel?.Dispose();
}
}