聊天频道
This commit is contained in:
51
Hotfix/Chat/System/ChatChannelCenterComponentSystem.cs
Normal file
51
Hotfix/Chat/System/ChatChannelCenterComponentSystem.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user