Files
Fishing2Server/Hotfix/Chat/System/ChatChannelCenterComponentSystem.cs
2025-08-12 14:05:23 +08:00

71 lines
1.9 KiB
C#

using Fantasy.Entitas;
using Fantasy.Entitas.Interface;
using Fantasy.Helper;
namespace NB.Chat;
public class ChatChannelCenterComponentAwakeSystem : AwakeSystem<ChatChannelCenterComponent>
{
protected override void Awake(ChatChannelCenterComponent self)
{
}
}
public class ChatChannelCenterComponentDestroySystem : DestroySystem<ChatChannelCenterComponent>
{
protected override void Destroy(ChatChannelCenterComponent self)
{
self.Channels.Clear();
}
}
public static class ChatChannelCenterComponentSystem
{
/// <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 ChatChannel? channel)
{
return self.Channels.TryGetValue(channelId, out channel);
}
/// <summary>
/// 申请创建一个频道
/// </summary>
/// <param name="self"></param>
/// <param name="unit"></param>
/// <param name="channelId"></param>
/// <returns></returns>
public static ChatChannel Apply(this ChatChannelCenterComponent self, ChatUnit unit, long channelId)
{
if (self.Channels.TryGetValue(channelId, out var channel))
{
return channel;
}
channel = Entity.Create<ChatChannel>(self.Scene, channelId, true, true);
channel.Creator = unit.Role.RoleId;
channel.CreateTime = TimeHelper.Now;
self.Channels.Add(channelId, channel);
return 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();
}
}