46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
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;
|
|
}
|
|
} |