51 lines
1.4 KiB
C#
51 lines
1.4 KiB
C#
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();
|
|
}
|
|
} |